0

I have written a desktop application (Windows Forms) in .NET Framework 4.0 using Visual Studio 2010 and SQL Server 2008.

In the /bin folder, it creates an .exe file which works fine on my computer and other computers if they have Visual Studio and SQL Server installed. If they do not have these installed, then it gives report error and the .exe file does not run.

On another PC, I have tested it both on Windows XP sp3, Windows 7 after installing .NET Framework 4.0, and also installed Windows Installer 4.5 for WinXP sp3, but no success.

What is the problem? Is there anything wrong with my connection string which is:

@“Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";

How can I make my .exe file run on other PCs?

Thank you, this helped a lot and now I understand the problem is only connection string but problem still not solved. Now I am using this connection string

Data Source=HOME-9BE0D501F6\SQLEXPRESS;AttachDbFilename=|DataDirectory|\shopdb.mdf;Integrated Security= True;User Instance=True

WA-PC was the name of my computer where I was working and it worked fine but when I copied the bin folder to my other pc with name HOME-9BE0D501F6 it still did not worked. I have changed the connection string in app.config file with this name but still got connection error. I have not installed SQL Server 2008 on this pc. Do I have to install it? What else I have to do?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

3 Answers3

0

.\SQLEXPRESS means SQL Express instance on local pc, so if no SQL Server installed, then you will get an error.

Giannis Paraskevopoulos
  • 18,261
  • 1
  • 49
  • 69
0

change the connection string with proper server name

Data Source=<servernameinwhichSQLServerInstalled>\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";

If you are using (local) or DOT(.) It means that it has to connect to computer in which application is running. In this case if you dont have sql server or database installed on different computer it will throw this error.

Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42
  • Please specify example for , what i can write here. I dont understand what will come here as it will run on different machines, so which server name. – user2798264 Oct 10 '13 at 13:16
  • you system name or IP in which application is going to installed – Rajesh Subramanian Oct 10 '13 at 13:16
  • I used this: Data Source=HOME-9BE0D501F6\SQLEXPRESS; but still did not work for me. Do i have to install sql server 2008 on that machine also? What else i have to do – user2798264 Oct 10 '13 at 18:35
0

The problem (as already mentioned) is that you are telling the SQL connection to use the local PC name and not the name of the server (where the SQL instance is installed).

A simple way to find this could be to open your SQL Managment Studio / Query Analyser / WinSQL / SQL Script editor and run the following script

use [Database name in question]
Select @@ServerName

Replace your;

Data Source=.\SQLEXPRESS

With

Data Source=@@ServerNameResult\SQLEXPRESS

Hope that helps.

Hexie
  • 3,955
  • 6
  • 32
  • 55
  • I used this: Data Source=HOME-9BE0D501F6\SQLEXPRESS; but still did not work for me. Do i have to install sql server 2008 on that machine also? What else i have to do – user2798264 Oct 10 '13 at 18:35
  • Yes, you would need SQL Server installed on that workstation / networked machine as well, remember you are trying to attached a .mdf file, hence, needing SQL Server. PS: Did you run the above mentioned SQL script to get that SQL Server name, it could be right - just a really long name. – Hexie Oct 11 '13 at 06:17
  • @user2798264 Thats great, if you could please `mark this as the answer` and upvote it (click on the up arrow next to the 1 - on the left of the question), would be greatly appreciated. – Hexie Oct 15 '13 at 10:12