Set Connection String at Run Time RRS feed

  • 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?



    • 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


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.


    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.


    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.


    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:



    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Monday, October 8, 2012 9:01 PM