简体   繁体   中英

How to Run Windows Form Application with SQL Server Database on Another Computer

I'm using Visual Studio 2015 and I just created a Windows Forms application with a SQL Server database. I finished the program and tried to run the application on the other computer but it didn't run. I also tried to install .Net Framework v4.0 and SQL Server Express on that computer and also put the database in path C:\\ so that the SqlConnection path on my computer to another computer will be the same.

The code is like this:

SqlConnection cn;
SqlCommand cm;
SqlDataReader dr;

string connection = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Database1.mdf;Integrated Security=True";

But I got an error that is the database I placed in path C:\\ is not writable whatsoever. I want to know what I can do in order to run the application.

You must install SQL Express on the computer/server where you want to have the database and then attach the MDF file.

Important: - Remember to open port 1433 in the Windows Firewall. - If you are going to use SQL Server authentication, you must create and / or activate the user with the desired password. - To connect you can use the IP of the computer/server, preceded by the instance of sql express. Example: YourIP\\SQLExpress

Good luck!

你需要为数据库创建共享服务器,然后,你可以访问你的数据库到任何地方和任何计算机谢谢

So much misunderstanding and misinformation around LocalDB.

While it was being developed, your application was using an edition of SQL Server called LocalDB . This is a low admin lightweight edition that lets you reference the MDF file directly (contrary to some comments here)

When you deploy your app you decide whether you want to stick with LocalDB or upgrade to a more scaleable edition of SQL Server.

In your case, I suggest you stick with LocalDB

There's some background here and a link to a video if you have time

LocalDB deployment on client PC

https://blogs.msdn.microsoft.com/sqlexpress/2011/07/12/introducing-localdb-an-improved-sql-express/

Now if you really want to an answer you need to post the exact error message that you see, not a vague recollection of it.

The problem might be that LocaDB is not installed, or it might be that there is some SQL Server access issue. We can't tell because you did not post the error message

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM