Home > Software design >  Connect Windows Forms application with SQL Server Express
Connect Windows Forms application with SQL Server Express

Time:01-09

I have created a Windows Forms desktop application using Visual Studio 2019. I also created a database using SQL Server Management Studio. I connected the database with my application with connection string

"Data Source=CYBERCELL\\SQLEXPRESS;Initial Catalog=Details;Integrated Security=True;"

The application is running without any error. I published this application using Visual Studio 2019 publish wizard and installed in another computer. But I can't understand how to use and connect the database with the application in that system.

I am looking to install SQL Server in every computer. But if I install SQL Server, the server name will be different.

CodePudding user response:

If you're locally installing SQL Server Express on each individual computer, you could use

.\SQLEXPRESS

or

(local)\SQLEXPRESS

as your server/instance name - this is the same on every computer. The dot . or (local) (in parenthesis) refers to the local computer, and SQLEXPRESS is the default instance name for any SQL Server Express installation.

CodePudding user response:

I once stuck with this same scenario... and this is how I solved the problem,

You don't have to install SSMS or SQL server on any of your client's pc, if you follow these steps

  1. You have to create a localDB on your application and make sure the application will connect to that localDB.(if you don't know how to connect to local db, here => Connect to LocalDB. And make sure to create tables and procedures as same as your previous database.

  2. Follow this answer(ticked) with code(connection string)

  3. After this, you have to install Advanced Installer to create an installer for your application (the best choice I ever chose).

  4. Then Follow this to create an installer where you make sure to add a prerequisite of localDB (say localdb 2019) installer of your current version.

  5. This makes your application run on any pc and only requires localdb as a prerequisite to be installed which also comes with the installer.

  6. Make sure to leave a message not to delete localdb on the application installed location.

  •  Tags:  
  • Related