标签:des style blog http io ar color os sp
在用VS自带的 .mdf读取(joint)时,报错:
1 Server Error in ‘/‘ Application. 2 An attempt to attach an auto-named database for file F:\cs\office\ReadWriterOffice\ReadWriterOffice\App_Data\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. 3 4 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 5 6 Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file F:\cs\office\ReadWriterOffice\ReadWriterOffice\App_Data\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. 7 8 Source Error: 9 10 Line 95: DB db = new DB("DBConnectionString"); 11 Line 96: using (SqlConnection conn = new SqlConnection(db.ConnectionString)) { 12 Line 97: conn.Open(); 13 Line 98: using (SqlCommand cmd = conn.CreateCommand()) { 14 Line 99: cmd.CommandText = sql; 15 16 17 Source File: F:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs Line: 97 18 19 Stack Trace: 20 21 [SqlException (0x80131904): An attempt to attach an auto-named database for file F:\cs\office\ReadWriterOffice\ReadWriterOffice\App_Data\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.] 22 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009598 23 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234 24 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275 25 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35 26 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183 27 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239 28 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195 29 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232 30 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185 31 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33 32 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524 33 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 34 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479 35 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108 36 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126 37 System.Data.SqlClient.SqlConnection.Open() +125 38 ReadWriterOffice.Samples.TransmitLonLa.ExportExcel() in F:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs:97 39 ReadWriterOffice.Samples.TransmitLonLa.Page_Load(Object sender, EventArgs e) in F:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs:24 40 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 41 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 42 System.Web.UI.Control.OnLoad(EventArgs e) +91 43 System.Web.UI.Control.LoadRecursive() +74 44 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207 45 46 47 48 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
解决方案是将连接字符串中的"AttachDbFilename"指定为绝对目录.
经过测试,我发现不是(joint)特殊,其实普通的select语句也会报一样的错,我猜想原因是sql比较特殊,这里应该是找不到,因为我的数据库比较大,所以我是从别的地方拷贝过来的,应该是日志文件不一致.所以需要制定绝对路径.
An attempt to attach an auto-named database for file
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/listened/p/4122344.html