Answered by:
Set Connection String at Run Time

Question
-
I have a database application built to run on a local network against an SBS server and SQL Server Express. It uses a disconnected model and was built using the Strongly-Typed database facility within VS (c# .net). This has worked fine for several years.
I now wish to transfer this to a different server, while retaining a test facility (ie the ability to test against a test database) on the present server and another test facility on the new server. Clearly each facility needs a different connection string. Currently, the connection string is fixed and buried in the app.config file.
Obviously the connection string can be changed with different builds for each instance. However, it would be much more convenient to store the connection string in the registry, where it could be updated if required and to use program logic to select and set the appropriate connection string before opening the database.
How, where (in which class) and at what stage could such a change be made within the program logic, please?
David
David
- Moved by Vicky SongMicrosoft employee Friday, October 5, 2012 2:51 AM (From:Visual Studio Database Development Tools (Formerly "Database Edition Forum"))
Friday, September 28, 2012 9:35 AM
Answers
-
See if one of these forums will help you:
http://social.msdn.microsoft.com/Forums/en-US/category/sqlserver/
Thanks!
Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)
- Proposed as answer by Ed Price - MSFTMicrosoft employee Monday, October 8, 2012 9:01 PM
- Marked as answer by Just Karl Monday, October 15, 2012 1:42 PM
Monday, October 8, 2012 9:01 PM
All replies
-
Hi David,
Thanks for your post. However, based on your description, I think that here is not the correct forum for you to deal with your issue. The forum here is mainly about developing database projects in the VS. What kind of project you are working with? I would like to help you move it to the correct forum.
Thanks.
Vicky Song [MSFT]
MSDN Community Support | Feedback to us
Monday, October 1, 2012 6:54 AM -
Hi Vicky,
Thanks for your response. This forum seemed the closest of the those available.
The application extracts selected records from the database of an accounting system, runs them against a (separately maintained) database of currency exchange rates, account conversions, etc. and feeds back a summarised schedule for reading into an Excel spreadsheet. It has been entirely built using VS and its database facilities. The large volume of generated code makes it difficult for me to see how to apply an alternative connection string - this is my problem. There seems to be little or no documentation on the VS strongly-typed database access builder tool anywhere.
If this is not the correct forum, I shall be grateful if you could point me to a better one.
Regards, David.
David
Monday, October 1, 2012 8:47 AM -
Hi David,
What kind of project you are working with? I am sorry that I still not very sure about your scenario. As database project (the forum mainly deal with) only contains database objects in the SQL Server (tables, views and stored procedure), it does not contain data stored in the database, so I think here is not the correct forum for you.
Thanks.
Vicky Song [MSFT]
MSDN Community Support | Feedback to us
Monday, October 1, 2012 8:53 AM -
See if one of these forums will help you:
http://social.msdn.microsoft.com/Forums/en-US/category/sqlserver/
Thanks!
Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)
- Proposed as answer by Ed Price - MSFTMicrosoft employee Monday, October 8, 2012 9:01 PM
- Marked as answer by Just Karl Monday, October 15, 2012 1:42 PM
Monday, October 8, 2012 9:01 PM