1

I'm trying to set my connection string in my Entity Framework at runtime. In an attempt to do this, I have the following code:

string connectionString = "tcp:[serverName],[port];initial catalog=[databaseName];user id=[userName];password=[pwd];MultipleActiveResultSets=True;App=EntityFramework";
using (MyEntities entities = new MyEntities(connectionString))
{
  MyEntity entity = new MyEntity();
  // Set entity properties here

  entities.MyEntities.Add(entity);
  entities.SaveChanges();
}

When I get to the line that says entities.MyEntities.Add(entity), an exception is thrown. That exception has the following information:

Type: ArgumentException
Message: Keyword not supported: 'tcp:[serverName],[port];initial catalog'.

Why won't the code that I've written work? For the life of me, I can't figure it out.

Thank you!

1 Answer 1

2

You're missing "Server":

string connectionString = "Server=tcp:[serverName],[port];initial catalog=[databaseName];user id=[userName];password=[pwd];MultipleActiveResultSets=True;App=EntityFramework";

(Assuming you are just substituting [serverName], [port], [databaseName] into the code in your question to hide the sensitive details. Obviously [serverName] isn't a valid hostname.)

I'm not 100% sure that "Server" and "Initial Catalog" work together, so you may need "Data Source" instead of "Server", or "Database" instead of "Initial Catalog".

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.