Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can not Connect to SQL Express using Visual Studio

Status
Not open for further replies.

Buffie

Programmer
Dec 4, 2003
15
US
I am trying to connect to a SQL Express database by using a connection string from a VB Windows application in Visual Studio but I get the following error. I tried getting a solution in the Microsoft SQL Server: Programming forum but was unable to. I am using the latest version of Visual Studio, Sql Express and XP sp2. Any help would be appreciated. I am trying to do this on my laptop and no one else has access to the file. I can go to the SQL Server Management Studio and look at the tables and data and so forth. TIA.

Error:
Unable to open physical file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\myfile.mdf". Operating system error 32: 32(The process cannot access the file because it is being used by another process.)" An attempt to attach an auto-named database for file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\myfile.mdf" failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
 
Buffie,
You may have better luck if you post this question in a VB forum. I can tell you this, by the error it appears that you are trying to conect to the database file. You can't do that.
the .mdf and ldf files are locked by SQL Server. You have to login to the instance with something like this.

Code:
StrConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;UID=[b]You user ID[/b]; Initial Catalog=[b]Your db[/b];Data Source=[b]Your DataSource[/]

This is an old connection string. I haven't had to create an application connection in a long time.

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Check for connection string information for SQL Server 2000 and SQL Server 2005.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top