将数据库文件从SQLEXPRESS复制到程序文件夹 [英] Copying database files from SQLEXPRESS to program folder

查看:80
本文介绍了将数据库文件从SQLEXPRESS复制到程序文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我又来了

好的,因此我现在从SQL Server管理器中分离了数据库,并且如预期的那样,它不再连接,现在我从分离的数据库中添加了分离文件.mdf和日志文件,并为我提供了应用程序服务连接字符串,如下所示:如下所示,这是Web.config中的实际连接字符串:

hi guys, me again

OK so ive now detached the database from SQL Server manager, and as predicted it no longer connects, now ive added the detached files the .mdf and the log file from the detached database, and it has given me the application services connection string , as shown below, this is the actual connection string in the Web.config:

<pre><connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
      providerName="System.Data.SqlClient" />
    <add name="TravelShopConnectionString1" connectionString="Data Source=MATTHEW-PC\SQLEXPRESS;Initial Catalog=TravelShop;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>



现在我知道最下面的是通过SQLEXPRESS与我的家用计算机的直接连接,最上面的是从复制的文件生成的字符串,但是尝试在c#代码中使用该错误时,错误仍然相同,如下所示:



now i know the bottom one is the direct connection to my home computer through SQLEXPRESS, and the top one is the generated string from the copied file, but the error remains the same when trying to use it in the c# code like this:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);



是否需要是复制数据库的直接文件路径名?

这是错误:



does it need to be a direct file path name to the copied database?

this is the error:

[SqlException (0x80131904): An attempt to attach an auto-named database for file 
C:\Users\Matthew\Desktop\testing conections\TheTravelShop\TheTravelShop\App_Data\aspnetdb.mdf failed.
A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.



这到底是什么意思?除了已经存在之外,尽管我确实将原始资源从服务器资源管理器中的应用程序中排除.


感谢您的阅读
Matt.



what does this actually mean? apart from it already exists, although i did exclude the original from the application in the server explorer.


Thanks for reading
Matt.

推荐答案

愚蠢的我....

Stupid me....

<add name="ApplicationServices" connectionstring="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providername="System.Data.SqlClient" />




没有将.mdf文件的直接名称从aspnetdb.mdf更改为TravelShop.mdf.

最简单的事情……

感谢您的观看
问候
马特.




didnt change the direct name of the .mdf file from aspnetdb.mdf to TravelShop.mdf.

the most simplest of things......

Thanks for viewing
Regards
Matt.


这篇关于将数据库文件从SQLEXPRESS复制到程序文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆