I have a winform app that will need to install SQLExpress with it. How can I predict what the SQL instance will be called so that my connection strings will all still work. ./SQLEXPRESS? username/SQLEXPRESS? or something else entirely?
Thanks!
I have a winform app that will need to install SQLExpress with it. How can I predict what the SQL instance will be called so that my connection strings will all still work. ./SQLEXPRESS? username/SQLEXPRESS? or something else entirely?
Thanks!
Why do you have your connection strings hardcoded? You really should have the enduser have the option to change where the database is located.
First, deploy the database as a data file. It will then be placed into the folder defined by ApplicationDeployment.DataDirectory (when it's deployed), or Application.StartupPath (when you're testing).
Then you need to check the context in which your program is running:
string databaseLocation;
if (ApplicationDeployment.IsNetworkDeployed)
{
databaseLocation = ApplicationDeployment.CurrentDeployment.DataDirectory;
}
else
{
databaseLocation = System.Windows.Forms.Application.StartupPath;
}
databaseLocation = System.IO.Path.Combine(databaseLocation, "databasename.mdf");