Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a DB using following code.

Dim conn As New SqlConnection("Server=.\SQLExpress;Data Source=;Integrated Security=SSPI")
       Dim cmd As New SqlCommand("", conn)
       cmd.CommandText = "CREATE DATABASE MyDBTest22 ON ( FILENAME = 'D:\dbTestATTTTTTT.mdf' ), ( FILENAME = 'D:\dbTestATTTTTTT_log.ldf' ) FOR ATTACH"

It ran without any error but when I opened SSMS, I could not see my file attached to the server. Also, I tried to make a connection, but it says file does not exist but when I tried to re-run the above code, it says File already exists.

Something wrong with my way of doing it? I want to see it attached with the instance of my SQL Server Express 2005, using SSMS.
Christian Graus 10-Feb-12 11:43am    
"Data Source=;" This works ?
Furqan Sehgal 10-Feb-12 12:56pm    
It did not give any error but did not work in the desired way either.
Shall I use data source=master?
Furqan Sehgal 11-Feb-12 4:29am    
I added master to Data Source but now error changed.
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
I have checked SQL server is set to allow remote connections and also exception in the firewall has been made.

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

  Print Answers RSS

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