在用VS自带的 .mdf读取(joint)时,报错:

 Server Error in '/' Application.
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. 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. 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. Source Error: Line : DB db = new DB("DBConnectionString");
Line : using (SqlConnection conn = new SqlConnection(db.ConnectionString)) {
Line : conn.Open();
Line : using (SqlCommand cmd = conn.CreateCommand()) {
Line : cmd.CommandText = sql; Source File: F:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs Line: Stack Trace: [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.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +
System.Data.SqlClient.SqlConnection.Open() +
ReadWriterOffice.Samples.TransmitLonLa.ExportExcel() in F:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs:
ReadWriterOffice.Samples.TransmitLonLa.Page_Load(Object sender, EventArgs e) in F:\cs\office\ReadWriterOffice\ReadWriterOffice\Samples\TransmitLonLa.aspx.cs:
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +
System.Web.UI.Control.OnLoad(EventArgs e) +
System.Web.UI.Control.LoadRecursive() +
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) + Version Information: Microsoft .NET Framework Version:4.0.; ASP.NET Version:4.0.30319.1

解决方案是将连接字符串中的"AttachDbFilename"指定为绝对目录.

经过测试,我发现不是(joint)特殊,其实普通的select语句也会报一样的错,我猜想原因是sql比较特殊,这里应该是找不到,因为我的数据库比较大,所以我是从别的地方拷贝过来的,应该是日志文件不一致.所以需要制定绝对路径.

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

An attempt to attach an auto-named database for file的更多相关文章

  1. Attempt to fetch logical page (...) in database 2 failed. It belongs to allocation unit xxxx not to xxx

    今天一个同事说在一个生产库执行某个存储过程,遇到了错误: Fatal error 605 occurred at jul 29 2014 我试着执行该存储过程,结果出现下面错误,每次执行该存储过程,得 ...

  2. Odoo Auto Backup Database And Set Linux task schedualer

    First ,Write Database Backup Script: pg_dump -Fc yourdatabasename > /home/yourfilepath/yourdataba ...

  3. 什么时候会刷新备库控制文件refresh the standby database control file?

    通过合理的设置,对于Primary的绝大数操作,都是可以传递到Physical Standby,datafile的操作是通过STANDBY_FILE_MANAGEMENT参数来控制的,但是即使STAN ...

  4. backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

    昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx> ...

  5. ArcCatalog连接ArcSDE连接报:unable to create new database connection file,permission is denied

    参考博文:链接 ArcCatalog连接ArcSDE连接报:unable to create new database connection file,permission is denied 最近经 ...

  6. SharePoint Config database Log file too big – reduce it!

    SharePoint Config database logs are one thing to keep an eye on since they do have a tendency to gro ...

  7. AdventureWorksDW2008R2 attach: Unable to open the physical file. Operating system error 5: "5(Access is denied.)

    http://stackoverflow.com/questions/26014133/adventureworksdw2008r2-attach-unable-to-open-the-physica ...

  8. attempt to write a readonly database错误的解决(C#,SQLite)

    今天打包WPF程序,安装后总是打不开,查看监控日志原来是SQLite的问题,报错如图 当向SQLite数据库中存入新纪录时总是显示attempt to write a readonly a datab ...

  9. 【原】Configuring Oracle Data Guard In Physical Standby Database

    作者:david_zhang@sh [转载时请以超链接形式标明文章] http://www.cnblogs.com/david-zhang-index/p/5042640.html参照文档:https ...

随机推荐

  1. Js点餐加减数量

    <button class="add-on" onclick="chgNum(1,'del')" ><i class="icon-m ...

  2. C#编写的序列化通用类代码

    using System; using System.IO; using System.IO.Compression; using System.Runtime.Serialization.Forma ...

  3. 转:assert()函数用法总结

    assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h>void assert( in ...

  4. SPRING-MVC访问静态文件,如jpg,js,css

    如何你的DispatcherServlet拦截 *.do这样的URL,就不存在访问不到静态资源的问题.如果你的DispatcherServlet拦截“/”,拦截了所有的请求,同时对*.js,*.jpg ...

  5. library cache lock

    SESSION 34 执行存储过程: SESSION 43 编译存储过程: SESSION 25 删除存储过程: 1.查询查看library cache lock等待事件的相关会话 SQL> s ...

  6. 【HDOJ】4986 Little Pony and Alohomora Part I

    递推.设n个盒子的Spell次数为S(n),期望为E(n).当有n个盒子时,可能第n把钥匙在第n个盒子中,此时的Spell次数应该为(n-1)!+S(n-1):当第n把钥匙不在第n个盒子中,混合排列, ...

  7. Silverlight 模板(Template)使用

    模板(Template)是控件另一种样式 它和样式(style)不同的是它允许已有的控件进行组合新的一个控件样式 那么先看一下最简单Template代码 xaml代码 <Button Conte ...

  8. C++ STL之set常用指令

    set,关联容器,元素不允许有重复,数据被组织成一棵红黑树,以牺牲插入和删除元素的效率换来了查找元素的高效率(O(logN)). 1.初始化 set<int> st; 2.begin返回第 ...

  9. openStack 云平台使用一般杂记

    1. To launch an instance,you must at least specify the flavor,image name,network,security group,keyp ...

  10. 通过百度获取IP地址对应的经纬度

    /** * 获取指定IP对应的经纬度(为空返回当前机器经纬度) *  * @param ip * @return */ public static String[] getIPXY(String ip ...