I have this auto-generated connection string in my app.config file. This was produced by making a database-first model in Entity Framework:
<add name="HalloweenContext" connectionString="metadata=res://*/HalloweenDbModel.csdl|
res://*/HalloweenDbModel.ssdl|
res://*/HalloweenDbModel.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=localhost\sqlexpress;
initial catalog=Halloween;
integrated security=True;
MultipleActiveResultSets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
I've been instructed to take that connection string and put it in the application settings (image is to illustrate the application settings page):
I've taken this section and cut/pasted it into a settings variable called "HalloweenContext" and also changed the "e;
to a single-quote:
"metadata=res://*/HalloweenDbModel.csdl|
res://*/HalloweenDbModel.ssdl|
res://*/HalloweenDbModel.msl;
provider=System.Data.SqlClient;
provider connection string=';
data source=localhost\sqlexpress;
initial catalog=Halloween;
integrated security=True;
MultipleActiveResultSets=True;
App=EntityFramework';"
providerName="System.Data.EntityClient"
However, when I paste this above selection into the application settings variable for HallowContext, I get the following error message:
I've checked the connection string and rechecked it, but I can't figure out what's wrong with it. I've removed quotes, added quotes, etc. but nothing seems to work for me.
I'm wondering if, perhaps, since this is an EF connection string, that I'm putting it into the application settings incorrectly?
UPDATE: After using the new data connection string outlined in the answer below, I am now getting a new error:
The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development. This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection...
So, I'm thinking that I may not be able to use this context in lieu of my db-first context. But, I also can't seem to use my db-first context as it is, so I'm at a standstill. I'll keep looking for a solution, and I do appreciate the help given so far.
As an added note, I'll restate that the original connection string works fine and is in the app.config file. However, I've been instructed to add it to the application settings. Personally, I feel that if it works in the app.config file, then that should be enough, but we've been instructed to use the connection string by adding it to the application settings and using it like connectionString = Settings.Default.HaloweenContext
. The ultimate goal is to have many connection strings set up in the application settings that we can use.
SIDE NOTE: I'm of the belief that using multiple named connection strings in the app.config file is the way to go. Is there any advantage to adding those connection strings as application settings instead of just manually adding them to the app.config file?