|
-
Dec 4th, 2006, 11:20 PM
#1
Thread Starter
Lively Member
Unable to connect to the Pubs.mdf database file
Hi,
I am using vb2005 to try to connect to the PUB.MDF database file. I copied the file into the same folder as the vb code files.
I used the statement below as the sqlConnection:
dim myConnection as SqlConnection = new _
SqlConnection("server=(local);database=pubs;uid=sa;pwd=")
When the program runs, there was a run time error and vb highlighted the line "myConnection.open()" and said that there was an error connecting to the database.
How do I solve this problem?
I did not set any password and userID to the database file. I tried removing the uid and pwd parameters but the error remains.
Last edited by LiLo; Dec 8th, 2006 at 02:52 AM.
-
Dec 4th, 2006, 11:40 PM
#2
Re: [2005] Unable to connect to the Pubs.mdf database file
That's not the correct connection string for attaching an MDF file to an SQL Server. That connection string is for connecting to a database contained in the SQL Server itself. If you're trying to attach your own file, or any third party file that hasn't been created by the SQL Server itself, then you need to specify the file by path. See www.connectionstrings.com for various connection string formats. See the SQL Server 2005 section for the correct format to attach an MDF file on connection.
-
Dec 5th, 2006, 09:45 PM
#3
Thread Starter
Lively Member
Re: [2005] Unable to connect to the Pubs.mdf database file
I have tried to attach the following connection string from the sql server 2005 section of connectionstrings.com but still there is an error.
The string is:
Dim myConnection As SqlConnection = New SqlConnection("Server=.\SQLExpress;AttachDbFilename=C:\Database Files\pubs.mdf;Trusted_Connection=Yes;")
But the error now is "An attempt to attach an auto-named database for pubs.mdf failed. The specified file cannot be opened"
When I added the 'Database=dbname' parameter into the connection string, there was also an error about not being able to attach the file with database dbname.
-
Dec 8th, 2006, 02:52 AM
#4
Thread Starter
Lively Member
Re: [2005] Unable to connect to the Pubs.mdf database file
Anyone knows?
-
Dec 9th, 2006, 04:12 PM
#5
Addicted Member
Re: Unable to connect to the Pubs.mdf database file
Start a new project with just a blank form.
Display the Data Source Configation Wizard (Data / Add new Data Source).
Double-click on the DataBase icon.
Click on the "New Connection" button.
On the Add Connection string, Click on the "Change" button and select 'Microsoft SQL Server Database File'
Click on the "Browse" button and select the database you want.
Click on the "Test Connection" button to test it.
Click on the "Advance" button. The connection string is displayed on the button of the "Advanced Properties" screen. You can copy it to the clipboard and paste it into your code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|