Click here to Skip to main content
15,906,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Just after installing my application, I need to attach my DB to SQL server. I am using following code for it.

VB
Dim cmd As New SqlCommand()
       Dim vrMyConString As String = "Data Source=.\SQLExpress; INITIAL CATALOG=master; uid=sa; pwd=sa;"
       Dim conn As System.Data.SqlClient.SqlConnection = New SqlConnection(vrMyConString)
       cmd.CommandText = "sp_attach_db 'e:\dbTest.mdf', 'e:\dbTest.ldf'"
       ' conn.ConnectionString = "Data Source=.\SQLExpress; INITIAL CATALOG=master; uid=sa; pwd=sa;"
       conn.Open()
       cmd.CommandType = CommandType.StoredProcedure
       cmd.Connection = conn
       cmd.executenonquery()


It gives error on
cmd.executenonquery()
"Could not locate entry in sysdatabases for database 'sp_attach_db 'e:\dbTest'. No entry found with that name. Make sure that the name is entered correctly."

Please advise what do I need to do.
Thanks
Posted
Updated 27-Jan-12 5:34am
v2
Comments
ZurdoDev 27-Jan-12 10:57am    
Every time I have seen that error it has been correct. Make sure the connection string is right.
Furqan Sehgal 27-Jan-12 11:06am    
Could u kindly advise what could be wrong in the connections string. I am using Windows authentication mode and there is no password on it.
Furqan Sehgal 27-Jan-12 11:33am    
Password issue is resolved... Now it gives error on cmd.executenonquery()
Could not locate entry in sysdatabases for database 'sp_attach_db 'e:\dbTest'. No entry found with that name. Make sure that the name is entered correctly.

1 solution

Have you tried this?

Connecting to a SQL Server Express Database[^]

I would try the following in that section and see if you get any errors.

Otherwise I would look at user security to make sure they have enough permissions and that you can manually connect to the installed SQL Express through management studio etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900