复制到输出目录问题 [英] Copy to output directory problem

查看:70
本文介绍了复制到输出目录问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我只有1天的时间来回答它.我不知道为什么当我在数据库中将复制到输出目录"设置为不复制时.我想连接到数据库时收到此错误:
尝试为文件F:\ Schoo_Backup \ 3 \ Visual Studio 2008 \ Projects \ School_Project1 \ School_Project1 \ bin \ Debug \ SchoolDB.mdf附加自动命名的数据库失败.存在具有相同名称的数据库,或者无法打开指定的文件,或者该数据库位于UNC共享上.
-------------------------------------------------- ---
在我的AppConfig上,我像这样设置连接:
-------------------------------------------------- ---

I have a question that i have only 1 day to answer it. i dont know why when i set Copy to Output Directory in my database to do not Copy. i get this error when i''m want to connect to the database:
An attempt to attach an auto-named database for file F:\Schoo_Backup\3\Visual Studio 2008\Projects\School_Project1\School_Project1\bin\Debug\SchoolDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
-----------------------------------------------------
on my AppConfig i set the connection like this:
-----------------------------------------------------

<add name="SchoolDB">
          connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\School.mdf;Integrated Security=True;User Instance=True"
          providerName="System.Data.SqlClient" />

      <add name="School_Project.Properties.Settings.SchoolDBConnectionString">
          connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SchoolDB.mdf;Integrated Security=True;User Instance=True"
          providerName="System.Data.SqlClient" />
     </add></add>


-------------------------------------------------- -----
我在异常类中获得了StackSource属性:
-------------------------------------------------- --------


-------------------------------------------------------
I get the StackSource property in exception class:
----------------------------------------------------------

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe()
at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode()
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at School_Project.Login.Check_If_Valid() in F:\Schoo_Backup\3\Visual Studio 2008\Projects\School_Project1\School_Project1\Logint.cs:line 27

推荐答案

也许应用程序仍在使用数据库并且无法替换它.尝试关闭IDE并再次打开它.
maybe an application is still using the database and cannot replace it. Try closing the IDE and open it again.


这篇关于复制到输出目录问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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