0

I have been trying to get this work for last couple of days with no success.

This is what I have done so far.

string providerName = "System.Data.SqlClient";
string serverName = serverIPAddress;
string databaseName = myDBName;

SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();

sqlBuilder.DataSource = serverName;
sqlBuilder.InitialCatalog = databaseName;
sqlBuilder.PersistSecurityInfo = true;
sqlBuilder.MultipleActiveResultSets = true;
sqlBuilder.UserID = "sa";
sqlBuilder.Password = saPassword;

string providerString = sqlBuilder.ToString();

EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();

entityBuilder.Provider = providerName;

entityBuilder.ProviderConnectionString = providerString;

entityBuilder.Metadata = "res://*/TUModel.myModel.csdl|res://*/TUModel.myModel.ssdl|res://*/TUModel.myModel.msl";            
myEntities ctx = new myEntities(entityBuilder.ConnectionString);

The constructor in entity class look like

public myEntities(string connectionString) : base("name=myEntities")
{
}

When I run there is no error. However if I delete 'myEntities' connection string from app.config, then it throws exception. If I leave it as it is then it ignores the connection string in the code and use the one in app.config.

Any help would be greatly appreciated.

1 Answer 1

2

Your context constructor isn't passing your connection string in, instead it is passing through a fixed value of name=myEntities. Change it to this:

public myEntities(string connectionString) : base(connectionString)
{
}
Sign up to request clarification or add additional context in comments.

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.