Connect Windows Forms application with SQL Server Express - c#

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.

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.

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
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.
Follow this answer(ticked) with code(connection string)
After this, you have to install Advanced Installer to create an installer for your application (the best choice I ever chose).
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.
This makes your application run on any pc and only requires localdb as a prerequisite to be installed which also comes with the installer.
Make sure to leave a message not to delete localdb on the application installed location.

Related

ClickOnce application using SQL Server database

I'm trying to learn how to create a simple application using Visual Studio IDE in C#.
I wrote a little application that uses a local SQL Server database for reading and storing data. On my machine, the program seems to work normally, but when trying to install the application on client computer it seems unable to read from the database.
I've tried to include the following prerequisites to the publish properties but it doesn't work:
Microsoft .NET Framework 4.5.2
SQL Server 2012 Express LocalDB
Any ideas about the right way to do it?
Thanks to all.
You need to install SQL Server Express LocalDB (SqlLocalDB.MSI) on the computer you are deploying your ClickOnce application to.
Selecting "SQL Server Express LocalDB" in the Prerequisites window and using "Download prerequisites from the component vendor's web site" should take care of that:
If you do that it should install the LocalDB for you and any database errors are more than likely resulting from connection string errors or leaving Integrated Security enabled.
You need to test on a target computer which does not have "SQL Server Express LocalDB" installed and verify that after the ClickOnce deployment it is installed. This will confirm that the problem is not the missing prerequisites but the database access issues...

Deploy c# application with MySql database in VS 2015 using VS Publish Method

I have created a C# application with a MySql database in Visual Studio 2015. I want to deploy my project using the publish method in Visual Studio including the database. I do not know how to deploy the MySQL database so I can use my application on the target computer without installing any MySQL server or database manually. I want that when I install my application on the target computer, it will auto detect the database and work.
Please help. Thanks.
If you use database storage as server means there is no need to install SQL and mySql Database Software. But you need to configure database in webconfig

how to deploy localdb database with app

I am ready to finalize a winforms add in I have created for Excel which uses Add-In Express to publish.
This add in uses a sql server localdb database with mdf file.
My primary question is how to deploy the mdf file to target machines. So far, I have manually copied the mdf file to test machine, but when testing the add in it fails to connect to the file (localdb is installed).
Error message:
Exception Source: .Net SqlClient Data Provider
Exception Type: System.Data.SqlClient.SqlException
Exception Message: Cannot open database "MyDatabase" requested by the login. The login failed.
Is it even possible to just drop the mdf onto machine and everything work? If so, is there a guide somewhere that could help. Or do I have to generate the sql scripts to create the database locally? If I do have to generate the SQL scripts, is there a way to roll this up in the Click-Once deployment approach, or I do I need a seperate process?
This is how you deploy a WinForms application with LocalDB
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.
Follow this answer(ticked) with code(connection string)
After this, you have to install Advanced Installer to create an installer for your application (the best choice I ever chose).
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.
This makes your application run on any pc and only requires localdb as a prerequisite to be installed which also comes with the installer.
Make sure to leave a message not to delete localdb on the application installed location.

How to transfer the local database of wpf application from one computer to other?

I have created a local database in my WPF application,now i want to run the application on some other computer,now how to transfer the local database from one computer to other,and i dont want to create the database manually on other machine? Do we have to convert the database into some .exe file ? If yes,then how to do this or what is the best approach to implement this?
My application accesses its own database file in its own directory with this connection string:
System.Environment.CurrentDirectory + #"\Data\" + databaseFileName;
Please explain from scratch as i am new to this??
I suppose you're running your database in SQL Express. You can use SQL Server Management Studio (included in most SQL Server installers) to export your database, including data, to a .bacpac file.
In SQL Server Management Studio 2012, right click your database, select Tasks, then Export Data-tier Application... and go through the wizard.
Then connect SQL Server Management Studio to the SQL Express server of the target machine. You can do that by connecting Management Studio on your machine to the SQL Express running on the target machine (provided that a network connection exists between the two, and the target machine has been properly configured to accept the connection), or by also installing Management Studio on the target machine, then connecting it to the local server (.\sqlexpress).
Once connected, right click the Databases in the Object Explorer, select Import Data-tier application..., and go through the wizard.

Deploying Windowsform application with SqlServer 2012 Databse in Visual Studio 2012

How can I deploy a windows form application with sql server database. I've searched a lot, The problem is I want the actual .mdf file when the application got installed on a PC for backup purposes. When I tried the publish feature, it converts the .mdf file into .mdf.deploy. I don't want to attach it into Sql Server Management Studio. I want to publish it with the actual application as .mdf, Kindly guide me in right direction. Thanks
If you nose around on the MS SQL Server site, you find that you can include a 'silent installer' for SQL Server in your .NET project. This will download and install an instance of SQL Server Express as part of your installation process. Just having the .MDF in a folder is useless.
In effect, you have to make at least a few items of functionality that stand in for SSMS: in particular database backups, database compaction, DBCC CHECKDB, etc. You are installing a 'full blown' SQL server instance, with it's separate windows service and system account, so you should be aware of how that impacts your user machine. This gets interesting if it's being deployed to a laptop, particularly a laptop that might sit in a café exposing ports to public LANs.
In general this is a can of worms. It is better to mandate the installation of SQL Server Express first, with SSMS, and merely attach your database to the existing instance. This makes a lot of other operations better behaved.

Categories