I am having major issues connecting to SQL Server 2005 Express from Visual Basic 2005 Express, which I have tried on multiple PCs but to no avail. Can somebody please explain to me what I'm doing wrong?
1) I install SQL Server 2005 Express and Visual Basic 2005 Express (With .NET framework and SQL native client of course)
2) I open SQL Server using Management Studio and going in with windows authentication. It automatically sets the log on name to computername\SQLEXPRESS.
3) I create a new database called Test and add one table to it
4) I go into Visual Basic 2005 and create a new project.
5) I go to the projects application settings (Properties - Settings).
6) I set up a new connection string, choosing SQL server as the conection type and then on the Connection Properties window it asks me to select the mdf file for the database. I choose the file Test.mdf from the directory C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\
7) I click on Test Connection.
When I do this on two out of the three home PCs I get the error:
Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf".Operating system error 32: "32 (error not found)".
An attempt to attach an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
The third PC gives me a different error:
Cannot open user default database. Login failed. Login failed for user 'DAVE\David'.
I get the same errors when I try to use a connection string inside the code directly. Does anyone have a clue as to why these errors are occuring? Do I need to set up security or something else on the database first, or is there another reason? If anyone can please help me get to the bottom of this or provide a web address where I can get the answer (step by step instructions on how to connect) then I would be most grateful.
error code 32 means:
"The process cannot access the file because it is being used by another process."
So, either use a different file name for your connection in Visual Basic 2005, or try disconnect your connection in SQL Server using Management Studio.
|||pse post the Connection string... it seems like u r trying to attach a db called Test....
in the second error .. check what is the Default Database given for user DAVE\David.... the default database should exists and this user should be a user of that db.... for debuggin purpose ... just change the default database of this user to Master and try... it will connect...
Madhu
|||Hi, I get the same error as the original poster of this thread. I have no other database with similar name or anything, and i have not, as far as i know, any other connections to this database, since I just created it. Do you have any idea of how I should go about this?
Thanks
Niclas
sqlsql
No comments:
Post a Comment