Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone help me ?
Here is code for create connection in vb.net 2008 with sql server 2008
but the following error is produced by the code below:

VB
Dim con As New SqlConnection
        Dim dbp As String
        Dim dbSource As String
        dbp = "Data Source=.\SQLEXPRESS"
        dbSource = "Data Source=C:\Users\Administrator\Documents\mydata.mdf"

        con.ConnectionString = dbp & dbSource
        con.Open()
        MsgBox("DataBase is Now Open")
        con.Close()
        MsgBox("Database is Now Closed")


This is the error message:
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: SQL Network Interfaces, error: 25 - Connection string is not valid)
Posted
Updated 22-Dec-10 22:34pm
v3

This should help:

Server=.\SQLExpress;AttachDbFilename=FilePathHere;Database=DatabaseNameHere; Trusted_Connection=Yes;
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Dec-10 4:35am    
Good call! 5+
Hi Mudasar,

1.You connection string seem not ok , try to create test connection string using server explorer in visual studio and copy paste that string.

2.Check your remote area configuration of SQL Server and Checked TCP/IP and Named Pipe both.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 23-Dec-10 4:36am    
Nice catch! 5+

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