Can you tell me how to use the connection string value from the app.config file and not the hard codee values?
In a C# 2008 desktop/console application, I created the connections to the database using linq to sql. Everything worked fine until I moved the
code to point to a different database. Somehow the original database connections are being saved and the values from the app.config file
are not being used.
I tried to do what the following link: http://refat38.wordpress.com/2012/01/30/unpick-linq-to-sql-connection-string-from-application-settings/,
said to do however, I do not know what the following statement means to do from this link:
Now Right Click and open the Properties on your DAL or project containing your LINQ to SQL classes and remove the connection string “Application Setting” reference on the Settings tab.
I also tried to add the following to the *.designer.cs file:
base(ConfigurationManager.ConnectionStrings["esample.Properties.Settings.devtestConnectionString"].ConnectionString, mappingSource) and attached
a system.configuration file as a reference.
1. The following code is from the app.config file:
connectionString="Data Source=dev;Initial Catalog=devtest;Integrated Security=True"
Can you show me code and/or tell me how to solve this problem so I can obtain the value from the app.config file?
If you have the database code in a different project than the main project, the connection string could have been saved in that project, but is still using the app.config in the main project. I know I have seen this in Entity Framework.
if I remember correctly:
Find your "context" class. Propably something named (your DB name)DataContext. Press F12 to find file with it. It is autogenerated. Connection string is saved either as Attribute on that class or as string in 1 of constructors. Delete it.
This should work but if your app does not work I bet there is something wrong also. Like connection strings names differ.
No more Mister Nice Guy... >: |
Last Visit: 31-Dec-99 18:00 Last Update: 1-Sep-15 9:24