首页 > 解决方案 > 为什么我的本地 SQL Express 必须允许远程连接才能使用本地 MDF?

问题描述

当我将我的 VB.net 程序设置为从本地 MDF 数据库文件 (SQL) 中读取时,它告诉我需要远程连接。详情如下:

我有一个 Visual Studiovb.net应用程序。它需要一个数据库,所以我下载了 SQL Express 并运行了一个脚本来添加我的数据库。这工作得很好。然后我想把我的程序发给一个同事,我想我应该把数据库的MDF和LDF文件复制到程序的App_Data文件夹中,然后使用一个可以读取MDF的连接字符串。

连接字符串似乎没问题:

Server=.\SQLExpress;AttachDbFilename=C:\gideonwroteprograms\EchoTheory\Echo
Theory\bin\Debug\App_Data\EchoDatabase.mdf;Database=EchoDatabase;Trusted_Co
nnection=Yes;

但我收到一条消息说我现在需要允许远程连接(我认为这是一个安全风险)。
消息是:

System.Data.SqlClient.SqlException
  HResult=0x80131904
  Message=A network-related or instance-specific error occurred while 
establishing a connection to 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. (provider: SQL Network 
Interfaces, error: 26 - Error Locating Server/Instance Specified)
  Source=.Net SqlClient Data Provider

标签: sql-servervb.netconnection-string

解决方案


推荐阅读