Visual Studio Community Edition sql connect string

kunstena

New member
Joined
Dec 4, 2014
Messages
2
Programming Experience
10+
I am trying to connect to sql express which is integrated with Visual Studio Community Edition (2013).
this is my code and connect string.
Dim mycn As New Odbc.OdbcConnection
Dim strcn As String = "Data Source=(localdb)\v11.0;AttachDBFilename=|DataDirectory|\sqlserver.mdf;Integrated Security=True;Connect Timeout=30"
mycn.ConnectionString = strcn
mycn.open

my mdf file is sqlserver.mdf. I have also tried replacing |dataDirectory| with the path to the mdf file. I keep getting a "data source not found error when I try to open the connection. Can anyone help?
 
make sure, you make the mdf file. maybe you're wrong when you call the file.
i have a example about it, chech this.

Module Module1 'koneksi ODBC ke MY SQL
Public conn As OdbcConnection
Public da As OdbcDataAdapter
Public cmd As New OdbcCommand
Public ds As DataSet
Public datardr As OdbcDataReader
Public strcon As String


Public Sub konek()
strcon = "Driver={MySQL ODBC 3.51 Driver};database=lat_vs2010;server=localhost;uid=root"
conn = New OdbcConnection(strcon)
If conn.State = ConnectionState.Closed Then
conn.Open()
MessageBox.Show("Koneksi database berhasil", "Connection Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Module
 
I checked - the mdf file is there. I modified the code to make sure the connection was closed before attempting to open.
Still no go.
 
Back
Top