An attempt to attach a auto-named database for file

Source: Internet
Author: User
Tags stack trace

When using the VS self-brought. MDF read (joint), an error occurred:

1Server Errorinch '/'application.2An attempt to attach an auto-named database forFile 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 islocated on UNC share.3 4Description:an unhandled exception occurred during the execution of the current Web request. Please review the stack trace forMore information about the error andwhereIt originatedinchThe code.5 6Exception Details:System.Data.SqlClient.SqlException:An attempt to attach an auto-named database forFile 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 islocated on UNC share.7 8 Source Error:9 TenLine the: DB db =NewDB ("dbconnectionstring"); OneLine the:using(SqlConnection conn =NewSqlConnection (db. ConnectionString)) { ALine the: Conn. Open (); -Line98:using(SqlCommand cmd =Conn. CreateCommand ()) { -Line About: Cmd.commandtext =SQL; the  -  -Source File:f:\cs\office\readwriteroffice\readwriteroffice\samples\transmitlonla.aspx.cs Line: the -  + Stack Trace: -  +[SqlException (0x80131904): An attempt to attach an auto-named database forFile 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 islocated on UNC share.] ASystem.Data.SqlClient.SqlInternalConnection.OnError (SqlException exception, Boolean breakconnection) +5009598 atSystem.Data.SqlClient.TdsParser.ThrowExceptionAndWarning () +234 -System.Data.SqlClient.TdsParser.Run (Runbehavior runbehavior, SqlCommand Cmdhandler, SqlDataReader DataStream, Bulkcopysimpleresultset Bulkcopyhandler, Tdsparserstateobject stateobj) +2275 -System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin (Boolean Enlistok) + * -System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin (ServerInfo serverinfo, String newpassword, Boolean Ignoresniopentimeout, Timeouttimer timeout, SqlConnection owningobject) +183 -System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover (ServerInfo serverinfo, String newpassword, Boolean Redirecteduserinstance, SqlConnection owningobject, sqlconnectionstring connectionoptions, Timeouttimer timeout) +239 -System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist (SqlConnection owningobject, Timeouttimer timeout, sqlConnectionString connectionoptions, String newpassword, Boolean redirecteduserinstance) +195 inSystem.Data.SqlClient.SqlInternalConnectionTds. ctor (dbconnectionpoolidentity identity, sqlConnectionString connectionoptions, Object providerinfo, String NewPassword, SqlConnection owningobject, Boolean redirecteduserinstance) +232 -System.Data.SqlClient.SqlConnectionFactory.CreateConnection (dbconnectionoptions options, Object Poolgroupproviderinfo, Dbconnectionpool Pool, DbConnection owningconnection) +185 toSystem.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection (DbConnection owningconnection, Dbconnectionpool pool, dbconnectionoptions options) + - +System.Data.ProviderBase.DbConnectionPool.CreateObject (DbConnection owningobject) +524 -System.Data.ProviderBase.DbConnectionPool.UserCreateRequest (DbConnection owningobject) + the theSystem.Data.ProviderBase.DbConnectionPool.GetConnection (DbConnection owningobject) +479 *System.Data.ProviderBase.DbConnectionFactory.GetConnection (DbConnection owningconnection) +108 $System.Data.ProviderBase.DbConnectionClosed.OpenConnection (DbConnection outerconnection, dbconnectionfactory ConnectionFactory) +126Panax NotoginsengSystem.Data.SqlClient.SqlConnection.Open () + the -ReadWriterOffice.Samples.TransmitLonLa.ExportExcel ()inchF:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs: the theReadWriterOffice.Samples.TransmitLonLa.Page_Load (Object sender, EventArgs e)inchF:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs: - +System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr FP, object o, Object T, EventArgs e) + - ASystem.Web.Util.CalliEventHandlerDelegateProxy.Callback (Object sender, EventArgs e) + * theSystem.Web.UI.Control.OnLoad (EventArgs e) + the +System.Web.UI.Control.LoadRecursive () + About -System.Web.UI.Page.ProcessRequestMain (Boolean includestagesbeforeasyncpoint, Boolean includestagesafterasyncpoint ) +2207 $  $   -  -Version Information:microsoft. NET Framework Version:4.0.30319; ASP. NET Version:4.0.30319.1 
View Code

The solution is to specify "AttachDbFileName" in the connection string as an absolute directory.

After testing, I found that is not (joint) special, in fact, the ordinary SELECT statement will also report the same error, I guess the reason is that SQL is very special, this should be found, because my database is relatively large, so I copied from somewhere else, The log file should be inconsistent. Therefore, absolute paths need to be developed.

Ref:http://stackoverflow.com/questions/12566036/an-attempt-to-attach-an-auto-named-database-for-file-database1-mdf-failed

An attempt to attach a auto-named database for file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.