另一台电脑上的本地数据库文件连接错误 [英] Local database file connection error on another pc
问题描述
我的项目中有一个用于单个 mdf 文件的连接字符串:
I've a connection string in my project for single mdf file as:
Private conn As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|datadirectory|BillAdjustment.mdf;Integrated Security=True")
Private cmd As New SqlCommand
此连接在我的电脑上运行良好,但在另一台电脑上无法运行并出现错误:
This connection works perfect on my pc but don't work on another pc and gets error:
A network related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.
我的数据库安装在 appdata
文件夹中.有什么解决办法吗?
My database installs in appdata
folder.
is there any solution?
推荐答案
在构建之前尝试在先决条件中包含 SQL Server.
Try including SQL Server in the prerequisites before building.
在解决方案资源管理器中:
In Solution Explorer:
右键单击您的项目 -> 属性 -> 发布 -> 先决条件
Rightclick your project -> Properties -> Publish -> Prerequisites
在先决条件窗口中检查 SQL Server Express LocalDB(或您正在使用的任何东西):
In the Prerequisites window check SQL Server Express LocalDB (or whatever you are using):
这将在您的应用程序安装过程中将用户转发到 SQL Server 下载和安装.
This will forward the user to SQL Server download and installation during the installation of your application.
这篇关于另一台电脑上的本地数据库文件连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!