我创建了一个Windows窗体applicatie与本地数据库(.MDF)来存储和检索数据。 数据库,我连接到的是: C:\ProgramData\project\Database.mdf
I created a Windows form applicatie with a local database (.mdf) to store and retrieve data from. the database where I connect to is: C:\ProgramData\project\Database.mdf
当我发表我的项目,把该文件夹中我的数据库文件上的其他电脑,并尝试运行它,我得到的错误无法定位本地数据库运行时安装
when I publish my project and place my database file in that folder on a other pc and try to run it I get the error unable to locate a local database runtime installation
我的连接字符串是:
conn.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\ProgramData\project\Database.mdf"";Integrated Security=True";
所以能有人帮助我解决这个问题? ,因为一切都运行在我自己的电脑精
so could somebody help me with this problem? because everything runs fine on my own pc
推荐答案是否包含数据库申请文件?如果没有执行下列操作(至少这是我在做它):
Did you include the database as "Application File"? If not do the following (at least this is how I am doing it):
项目 - > 属性 - > 发布 - > 应用文件
Project -> Properties -> Publish -> Application Files
下面为您的.mdf和值的xx_log.ldf作为如下:
Here set the values for your .mdf and the xx_log.ldf as follows:
现在还在发布标签下去的先决条件。在这里,你必须检查这取决于你所使用的数据库中的以下内容。
Now still in the Publish tab go on Prerequisites. Here you have to check the following depending on what database you are using.
这将下载SQL Server Express的谁是安装应用程序的客户端。
This will download SQL Server Express for the client who is installing your application.
您还必须将连接字符串更改为通用路径。我想数据库介于项目文件夹/箱里面我猜,不知道了。因此,调整你的连接字符串是这样的:
You will also have to change the connection string to a generic path. I suppose the database lies somewhere inside your project folder /bin I guess, not sure anymore. So adjust your connection string to something like:
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True我therfor建议使用的资源文件或app.config中
I therfor recommend using a resource file or app.config
但基本上我认为你的问题是,你在PC上安装没有安装的SQL Server。因此,只要按照上面的先决条件中的步骤。其他的步骤使您无需将其移动到手动特定的文件夹数据库部署到项目文件夹。
But basically i think your problem is that the pc you are installing on does not have SQL Server installed. So just follow the steps above in Prerequisites. The other steps will enable you to deploy the database to the project folder without moving it to a certain folder manually.
我希望这有助于。
更多推荐
发布具有本地数据库的项目
发布评论