How to avoid writing multiple connection strings

PRAISE PHS

Well-known member
Joined
Jun 2, 2011
Messages
58
Programming Experience
Beginner
Hi All,

I have six forms on my windows app, each having their connection strings on their various public classes. But whenever I want to install my app on client's system, I always change the server name on each of my forms to the server name of my client's system and this gives me a lot of work.

Please how do I do it that I will have the connection strings for all my forms just in one place so that whenever I want to change the server name, I will just go to this single place and make the change. Pls, kindly help me out with on this.
 
Open the Settings page of the project properties and add a new setting of type Connection String. Configure your development connection string and it will be stored in the config file. Wherever you need the connection string in code, you use My.Settings.SomeConnectionString, where "SomeConnectionString" is the name of the setting you created. When you deploy the app, you simply edit the connection string by hand in the config file.

Note that, if you're using SQL Server, you can use a dot or "(local)" to refer to the local machine in your connection string. If the database is on the same machine as the app in both development and production, your connection string will work without change.
 
Open the Settings page of the project properties and add a new setting of type Connection String. Configure your development connection string and it will be stored in the config file. Wherever you need the connection string in code, you use My.Settings.SomeConnectionString, where "SomeConnectionString" is the name of the setting you created. When you deploy the app, you simply edit the connection string by hand in the config file.

Note that, if you're using SQL Server, you can use a dot or "(local)" to refer to the local machine in your connection string. If the database is on the same machine as the app in both development and production, your connection string will work without change.

Thanks Jim for the reply. But, please I don't get what you mean by "Configure your development connection string". Can you please explain this to me. Thanks.
 
Thanks Jim for the reply. But, please I don't get what you mean by "Configure your development connection string". Can you please explain this to me. Thanks.

I finally understood what you meant by "Configure your development connection string". But I'm finding it difficult to understand - "Note that, if you're using SQL Server, you can use a dot or "(local)" to refer to the local machine in your connection string". Can you pls expatiate more on this. Thank you.

Thanks a lot Jim. I finally figured out how to go about it. I'm really grateful for your info.
 
Last edited:
Back
Top