简体   繁体   English

.mdf文件数据库的WPF连接字符串

[英]WPF connection string for .mdf file database

I have a problem with publish of my WPF application. 发布我的WPF应用程序时遇到问题。

Database doesn't attach by project, and located in folder Debug , and connection string is : 数据库不按项目附加,位于文件夹Debug ,连接字符串为:

<connectionStrings>
    <add name="DataFormConnection"
         connectionString="Server=(localdb)\v11.0; Integrated Security=True;AttachDBFilename=|DataDirectory|\DBT.mdf; Connection Timeout = 30" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

Accession takes place after this string 加入发生在此字符串之后

In VS2012 it works great, but when I publish the application, database is not in the folder AppFiles . 在VS2012中,它工作得很好,但是当我发布应用程序时,数据库不在AppFiles文件夹中。

Just trying to publish database through installshield but also to no avail. 只是尝试通过installshield发布数据库但也无济于事。

How all the same right to register the connection string? 如何正确注册连接字符串? Thanks! 谢谢!

In Solution Explorer, right click your database file and select Properties. 在Solution Explorer中,右键单击数据库文件,然后选择Properties。 Make sure the "Copy to Output Directory" item is selected as "Copy always". 确保将“复制到输出目录”项目选为“始终复制”。

Now, every time you compile your application, your original database file is copied to the Debug folder. 现在,每次编译应用程序时,原始数据库文件都会复制到Debug文件夹中。

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

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