Microsoft KB Archive/908038

= You may receive an error message when you try to add a user control to a Windows Forms-based application if the user control contains a data-binding object that uses an attached local database file in Visual Studio 2005 =

Article ID: 908038

Article Last Modified on 6/12/2006

-

APPLIES TO


 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Express Edition
 * Microsoft SQL Server 2005 Express Edition

-





SYMPTOMS
When you try to add a user control to a Microsoft Windows Forms-based application in Microsoft Visual Studio 2005, you may receive the following error message:

An attempt to attach an auto-named database for file :\Program Files\Microsoft Visual Studio 8\Common7\IDE\ .mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

You experience this problem if the user control contains a data-binding object that uses an attached local database file.



CAUSE
This problem occurs because Microsoft SQL Server 2005 Express Edition lets you set the DataDirectory keyword. The DataDirectory keyword determines where SQL Server 2005 Express Edition looks for database files. When the connection string contains the text “|DataDirectory|”, SQL Server 2005 Express Edition replaces this text with the value of the DataDirectory keyword that you set. Then, SQL Server 2005 Express Edition connects to the database that uses this new connection string. By default, the value of the DataDirectory keyword is the current working folder of the Devenv.exe program that requests the connection to the database file. Because the database file is not located in the current working folder, you receive an error message.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



WORKAROUND
To work around this problem, use one of the following methods:
 * Put code in a method instead of in the Form_Load section of the application. Then, you can call the method when you have to.
 * Do not fill control data at design time. Instead, use the DesignTime property.



Steps to reproduce the problem
 Start Visual Studio 2005. On the File menu, point to New, and then click Project. Click Visual Basic Windows under Project types, and then click Windows Application under Template. Type in the Name box, type  :\ in the Location box, and then click OK. On the Data menu, click Add New Data Source.</li> In the Data Source Configuration Wizard, click Database, and then click Next.</li> In the Choose Your Data Connection dialog box, click New Connection. The Add Connection dialog box appears.</li> In the Add Connection dialog box, click Change.</li> In the Change Data Source dialog box, click Microsoft SQL Server Database File, and then click OK.</li> In the Add Connection dialog box, click Browse, locate and then click northwnd.mdf, and then click OK.</li> In the Data Souce Configuration Wizard, expand the tables, click the Customers table, and then click Finish.</li> In Solution Explorer, right-click  , click Add, and then click User Control.</li> In the Add New Item -  dialog box, click User Control, and then click Add.</li> In the Data Sources dialog box, add the Contact table to the UserControl control.</li>  Double-click the UserControl control, and then paste the following code example in the Control Load handler. Me.CustomersTableAdapter.Fill(Me.NorthwindDataSet.Customers) </li> Add the UserControl control to the Windows Form.

You receive the error message that is mentioned in the &quot;Symptoms&quot; section.</li></ol>

Keywords: kbtshoot kbprb KB908038

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.