简体   繁体   English

如何允许计算机连接到本地SQL文件

[英]How do I allow a machine to connect to local SQL file

I'm currently working on an EPOS system for a friends shop, I'm currently getting him too test the features, making sure design etc is fine. 我目前正在为朋友商店制作一个EPOS系统,我现在正让他测试这些功能,确保设计等都很好。 I've set up the SQL Service Based Database, but the problem seems too be he is getting the error 我已经设置了基于SQL服务的数据库,但问题似乎也在于他得到了错误

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. System.Data.SqlClient.SqlException(0x80131904):建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible. 服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。

I'm guessing this is because he hasn't got SQL Management server installed? 我猜这是因为他没有安装SQL Management服务器? I was wondering if there is anyway that I can include all of the required SQL files for him so that he can just open the program and then have it connect? 我想知道是否有任何我可以包含所有必需的SQL文件,以便他可以打开程序,然后连接?

Pastebin 引擎收录

My connection string within my code: 我的代码中的连接字符串:

  String connString = Settings.Default["DBConnectioNString"].ToString();
        SqlConnection conn = new SqlConnection(connString);
        if (conn.State != System.Data.ConnectionState.Open) conn.Open();

The DBConnectionString that is generated when creating the service based DB: 创建基于服务的DB时生成的DBConnectionString:

Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Databases\DB.mdf;Integrated Security=True

When I build the solution, it contains the database file exactly where I put it in VS17, any ideas on how I can make this work on his machine without him having to download SQL Management DB? 当我构建解决方案时,它包含数据库文件,我把它放在VS17中的任何想法,我怎么能在他的机器上使这个工作,而他不必下载SQL Management DB?

If someone can point me in the right direction, that would be appreciated, thank you. 如果有人能指出我正确的方向,那将不胜感激,谢谢。

Install SQL Express server. 安装SQL Express服务器。 And then use this: 然后用这个:
string connectionString="Data Source=.\\SQLEXPRESS;AttachDbFileName=|DataDirectory|\\DatabaseFileName.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True";


You must have SQL server installed. 您必须安装SQL Server。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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