我正在开发需要与SQL Server通信的Windows窗体应用程序。一旦连接字符串尝试连接到无效的地址,我正在部署应用程序时遇到问题。
I am developing a windows forms application that needs to communicate with the SQL Server. I'm facing a problem when I deploy the application once the connection string is trying to connect to an invalid address.
我已经搜索了很多,我发现连接字符串必须具有 | DataDirectory | 指令。现在.mdf文件位于目录 C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA 。实际上连接字符串是: connectionString =Server = .\SQLExpress; AttachDbFilename = | DataDirectory | PDVDatabase.mdf; Database = PDVDATABASE; Trusted_Connection = Yes;
I've already searched a lot and I found out the connection string must have the |DataDirectory| directive. Now the .mdf file is located on the directory C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA. Actually the connection string is:connectionString="Server=.\SQLExpress;AttachDbFilename=|DataDirectory|PDVDatabase.mdf;Database=PDVDATABASE;Trusted_Connection=Yes;"
我的应用程序连接到数据库的唯一方法是由Server Explorer(我使用的是Visual Studio 2013),其中我获取了我设置的.mdf文件的静态连接字符串在app.config中,但是在部署之后这种方式将不起作用。
The only way my app connects to the database is by the Server Explorer (I'm using Visual Studio 2013) where I get the static connection string of the .mdf file I set up in the app.config, but that way won't work after the deployment.
我的问题是:在部署之后如何连接我的应用程序,以便与.mdf文件通信? (我正在使用安装项目进行部署)。可能是错的?
My question is: How do I do to connect my app after the deployment in order to communicate with the .mdf file? (I'm using a setup project for deployment). What's can be wrong?
感谢。
推荐答案很多事情需要解决
1) You need a copy of your MDF and LDF files to be distributed with your app 2) You need to know if your user has Sql Server installed in its internal LAN or its PC If the previous condition is true then 3.1) You need to attach your copy to the end user Sql Server Instance 3.2) You need to change your connection string to point to the end user Sql Server Instance else 4.1) You need to distribute and install LOCALDB 4.1) You need to prepare the connection string for LOCALDB有些链接可以帮助您完成此任务
Some links to help you in this task
要附加和分离数据库信息 对于 LOCALDB 信息 LocalDb的Connectionstring 查找Sql服务器实例遍及您的网络
更多推荐
如何部署Windows窗体数据库应用程序
发布评论