Naveen's Weblog

Bridge to future

An attempt to attach an auto-named database for file xxxx.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Posted by codingsense on October 20, 2009



I got this error while opening a connection. So i googled for the solution and found that some changes are to be done in config file. But nothing happened after changing it as mentioned.

Then i noticed the error correctly and it was pointing correct MDF file but the path was wrong. Eventhough it was correctly mentioned in Config file.

Solution :
So i went to Properties folder -> Settings.Settings and saw that the connection string was not refreshed in it. Then i manually changed it to point to proper location of MDF file and all went right.

Thanks
Naveen Prabhu

Advertisements

7 Responses to “An attempt to attach an auto-named database for file xxxx.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.”

  1. sameer said

    what changes u have made.and where is property folder

    plz give me reply

    thanks in advance

    • codingsense said

      Hi Sameer,

      Open the properties -> settings in solution explorer you will see proper path, but when you open setting resx file you will find that the data that is seen in the grid in visual mode is not there in the view code mode. Update it properly and you will be able to connect to the database without any issue.

      Thanks,
      Codingsense

  2. Yash said

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.Data.SqlClient.SqlException (0x80131904): Database ‘E:\24 August 2011\InventorySystem\InventorySystem\bin\Debug\App_Data\Inventory.mdf’ already exists. Choose a different database name.
    Cannot attach the file ‘C:\Users\whizkraft\Desktop\App_Data\Inventory.mdf’ as database ‘Inventory’.
    at InventorySystem.ErrorHandeler.handle(Int32 Id, String MethodName)
    at InventorySystem.Login.btnLogin_Click(Object sender, EventArgs e)
    at System.Windows.Forms.Control.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnClick(EventArgs e)
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ButtonBase.WndProc(Message& m)
    at System.Windows.Forms.Button.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    —————————————-
    InventorySystem
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/whizkraft/Desktop/InventorySystem.exe
    —————————————-
    System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    —————————————-
    System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    —————————————-
    System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
    —————————————-
    System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    —————————————-
    System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
    —————————————-
    System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
    —————————————-
    System.Data.Linq
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Data.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Data.Linq.dll
    —————————————-
    System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
    —————————————-
    System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
    —————————————-
    System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
    —————————————-
    Anonymously Hosted DynamicMethods Assembly
    Assembly Version: 0.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll
    —————————————-

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.

    After I install my setup when I run it show this error Please help me

    • ajay said

      i am also facing the same problem plz reply me also.

      • codingsense said

        Hi Ajay,
        Have you checked this

        Open the properties -> settings in solution explorer you will see proper path, but when you open setting resx file you will find that the data that is seen in the grid in visual mode is not there in the view code mode. Update it properly and you will be able to connect to the database without any issue.

        Thanks,
        Codingsense

  3. Arvind Kumar said

    hurreyyyyyyyyyyyyy, i got the solution….
    Create a Asp.net folder by name “App_Data” in your project… close the project and paste your mdf and log database files here…

    now start the Visual studio….u’ll find the database file attached with your project..

    Hope it w’ll solve your problem

  4. palak said

    while copy-paste…its giving error as….. “Open Error:Access is denied.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: