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 (908038)
The information in this article 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
SYMPTOMSWhen 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 DriveLetter:\Program Files\Microsoft Visual Studio 8\Common7\IDE\DatabaseName.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.
CAUSEThis 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.STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.WORKAROUNDTo 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.
Modification Type: | Major | Last Reviewed: | 6/12/2006 |
---|
Keywords: | kbtshoot kbprb KB908038 kbAudITPRO kbAudDeveloper |
---|
|