-1

I am using Visual Studio 2010 for my windows application development and I have developed an application. Now I want to publish this application as a windows installer and I have done all the steps as below in the image.

enter image description here.

I have both the .mdf and the .ldf database files within the DATA folder. Within the code, i have given the connection string as below,

SqlConnection con = new SqlConnection(@"Server=.\SQLExpress;AttachDbFilename=DATA\\Database.mdf;");

I published the website and installed on my laptop. It gets installed and then runs but I am getting an error in the database as I have checked this with printing exception in the application. The error I obtained was

A network-related or instance-specific error occurred while establishing a connection to SQL Server

And the application takes too much time to load from one form to another. Is my connection string right or should I change it? Is there any way to make the forms load much faster?

Mano Prathibhan C
  • 488
  • 1
  • 11
  • 38
  • Where is your exe from the `Data` folder? it should be in the same location, other wise you should put a full path to the data folder. –  Sep 21 '17 at 14:49
  • Also you shouldn't use a fixed connection string in your code this way. You should put it in the app.config, so that you can change it any time you want without re building your application again. –  Sep 21 '17 at 14:50
  • My `.exe` is within the `Cheque Clearing 1.0` folder, same as the `DATA` folder – Mano Prathibhan C Sep 21 '17 at 14:51
  • Try to put a full path instead of just data like `D:\cheque clearing\data\data.mdf` –  Sep 21 '17 at 14:51
  • 1
    You are not showing, nor describing, the errors from teh database. – Ricardo C Sep 21 '17 at 14:52
  • Ok ok...I will try the full path. I can add an `app.config` fill manually myself? it doesn't have any such file as of now. – Mano Prathibhan C Sep 21 '17 at 14:53
  • Yes you can add add it from Visual studio. –  Sep 21 '17 at 14:54
  • But even so, when installing the user can select any directory he likes to install. How can we handle the connection string path that time? – Mano Prathibhan C Sep 21 '17 at 14:54
  • This is my error `A network-related or instance-specific error occurred while establishing a connection to SQL Server` – Mano Prathibhan C Sep 21 '17 at 15:07
  • Have you actually installed Sql Server Express edition on your laptop? – Chris Dunaway Sep 21 '17 at 16:01
  • When you attach a database to the SQL server then server owns the file and will not allow a connection to the mdf file. You must connect to the SQL Server and access the data base through the server. So the connection string doesn't contain the mdf filename. Instead use the SQL server name and database name. – jdweng Sep 21 '17 at 16:17
  • Yes, i have it installed SQL server express on my laptop. But I want this application to work in other systems also if I install there. I'm not sure how to do that. Can I still use the database name and SQL server name when I want to use this application in another remote system that is not connected to my laptop? – Mano Prathibhan C Sep 21 '17 at 16:40
  • The app works when I run it directly from VS 2010. Only after installation, it shows this error. – Mano Prathibhan C Sep 21 '17 at 16:51

1 Answers1

0

You have to choose yours from below 2 choices:

Installer with dependencies of Sql Express
Or
Clickonce deployment for Application & database

You have to try it out yourself which fits best for you, you may not get enough support with these old school stuffs.