Connecting Strings on C# (using visual studio) - making it general/generic
-
Hi, I have a problem that connects to my database (on the same machine) using the usual c#/vs connectionString. When I publish it, that string is still the same (i.e. the name of the machine doesn't change). Yea, I think I've hardcoded the connectionString. But how can I softcode it using VS? How can I make it so that the connectionString takes the name of the current machine it is residing on or better, the application would prompt for where the database is. Any help is appreciated? Or even just point me to articles. Thanks.
-
Hi, I have a problem that connects to my database (on the same machine) using the usual c#/vs connectionString. When I publish it, that string is still the same (i.e. the name of the machine doesn't change). Yea, I think I've hardcoded the connectionString. But how can I softcode it using VS? How can I make it so that the connectionString takes the name of the current machine it is residing on or better, the application would prompt for where the database is. Any help is appreciated? Or even just point me to articles. Thanks.
Just use the app.config - file to set up your connection-strings. It's easy to administrate and flexible (all you will need is a text-editor). If this is not what you want, use a static connection string and use string.replace to replace your computer name with the one you get from System.Net.Dns.GetHostName() (I don't recommend this - normaly another DB will require another login etc.)
-
Hi, I have a problem that connects to my database (on the same machine) using the usual c#/vs connectionString. When I publish it, that string is still the same (i.e. the name of the machine doesn't change). Yea, I think I've hardcoded the connectionString. But how can I softcode it using VS? How can I make it so that the connectionString takes the name of the current machine it is residing on or better, the application would prompt for where the database is. Any help is appreciated? Or even just point me to articles. Thanks.
Theres a ConnectionStringBuilder class in the framework somewhere that acts like a dictionary. Then you can add the machine name on at runtime.
Mark Churchill Director Dunn & Churchill Diamond Binding: Zero to Data Layer in 3 mins
-
Hi, I have a problem that connects to my database (on the same machine) using the usual c#/vs connectionString. When I publish it, that string is still the same (i.e. the name of the machine doesn't change). Yea, I think I've hardcoded the connectionString. But how can I softcode it using VS? How can I make it so that the connectionString takes the name of the current machine it is residing on or better, the application would prompt for where the database is. Any help is appreciated? Or even just point me to articles. Thanks.
Specify
localhost
as the server? I use custom configuration files; if the program can't find the file it pops up a dialog to get the names of the server and database from the user then stores that information in the configuration file.