0

I have a WinForms application that connects to a SQL Server database. I use the following connection string

data source=MyPC\SQLEXPRESS;initial catalog=MyDB; trusted_connection=true;

Problem is, I need to create an installer for the application, but I do not know the name of the target computer. How can I define my connection string, so it will work on any computer the application is installed on?

Thank you for your help.

5
  • Which tool do you use to create the installer? Commented Jan 19, 2014 at 19:41
  • 1
    Use "data source=.; and it will pickup any default instance of SQL Server installed on target machine. If you are sure that the instance name would be 'SQLEXPRESS; then "data source=.\SQLEXPRESS" Other options are embedded databseses like SQL Compact Edition. Commented Jan 19, 2014 at 19:53
  • @Kashif Yes, I'm almost certain it will be SQLEXPRESS (will ask one more, tho). Thanks, will try it on my mom's laptop, since she doesn't have anything installed on it yet :D Commented Jan 19, 2014 at 19:58
  • @Steve I will probably use SharpDevelop 4.4, since I think Visual Express will not allow me to create an installer Commented Jan 19, 2014 at 19:59
  • 1
    If the target machine does not have SQL Express installed then it wont work. Thats what I am telling you. If you are not sure that your users will have SQL Express or any other instance of SQL Server installed then you have to use then embedded databases (SQLite, SQL Compact Edition) and if you can ask (force) your users to install any instance of SQL Server then use this connection string to mention the instance name. BTW I am sure your moms computer wont have SQL Server until/unless she is like Julie Lerman -:) Commented Jan 19, 2014 at 20:04

1 Answer 1

2

I still don't have the privilege to comment, so I'm posting as an answer.

using "Localhost" in the data source would do the trick so your connection string will be like this:

connectionString="data source=localhost\SQLEXPRESS;initial catalog=MyDB; trusted_connection=true;"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.