1

I successfully created database on my local server using Code First, migrated it to Azure and now I want to connect to that database with using Azure connection string and my existing POCO clases.

My connection string:

<add name="CijenolomciContext" connectionString="Data Source=*.database.windows.net;Initial Catalog=NewCijenolomci;Persist Security Info=True;User ID=Bip*;Password=**;MultipleActiveResultSets=False&quot;" providerName="System.Data.EntityClient" />

but this section of code happens to do nothing on the server:

Item i = new Item();
            i.Name = "Cranberry";
            i.OldPrice = new decimal(25.99);
            i.NewPrice = new decimal(14.99);
            i.SaleStarts = DateTime.Parse("2012-01-21");
            i.CategoryID = 1;
            context.Items.Add(i);
            context.SaveChanges();

How to succesfully add it?

EDIT: This approach happens to modify my local DB, not the Server one.

2 Answers 2

1

It doesn't look like you're connecting to an Azure database to me. I'd expect a connection string more like this.

Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;Encrypt=True;

Use 'username@servername' for the User ID parameter.

See Connection Strings for SQL Azure.

Sign up to request clarification or add additional context in comments.

2 Comments

Whell i use this kind of connection string and it keeps to add to local DB :/
It may be because i inherit the base constructor in DbContext, but now when i change it i get System.ArgumentException: Keyword not supported: 'server'.
0

OK. Here it is. In DbContext i inherit base constructor:

 public CijenolomciContext()
        : base(*database name*)
    {
        //additional logic
    }

and despite that i add my connection string in App.config he was always connecting to the local.

I hardcoded Connection string and just add it in the constructor. Now it works! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.