2012-07-20 89 views
2

我在Linq-to-SQL连接中遇到了一些问题,我开发了一个使用Linq-to-SQL的桌面应用程序,因为我已经使用了基于服务的本地数据库,并且为此应用程序创建了一个设置,将.mdf文件放入我的安装项目,我现在的问题是,当我创建的设置和其他电脑上安装它,然后它会告诉我的错误一样运行时数据库连接期间的连接问题。

BA 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)lockquote

我的连接字符串是

connectionString="AttachDbFilename=|DataDirectory|\DailyExpense.mdf; 
        Integrated Security=True;User Instance=True" 
+1

那台电脑是否还安装了SqlExpress? – 2012-07-20 12:40:42

+1

是的,如果SqlExpress安装,那么它给我同样的错误。 – 2012-07-20 12:47:40

+1

是否需要在使用.mdf文件时安装客户端SqlExpress? – 2012-07-20 12:48:28

回答

1

你写的连接方式字符串表示您在目标计算机上安装了SQL Server 。您使用的格式“指示”您的应用程序试图将您提供的.mdf文件附加到sql server的本地RUNNING实例。如果您想使用远程服务器,则必须稍微重写连接字符串以指向服务器本身。您的连接字符串应该类似的东西:

data source=(MY MACHINE)\sqlexpress;initial catalog=DailyExpense;integrated security=True 

其中: - 我的机器会在其上的SQL Express实例运行服务器。 - sqlexpress是sql实例的名称(默认为sqlexpress)。 - DailyExpense是数据库的名称(假设数据库名称与您提供的mdf文件相同)。

+0

感谢您的回复,但我怀疑您的回复,如果我正在写数据源=(我的机器),它将如何在目标机器上工作? – 2012-07-26 14:32:50