vb.net - I cannot connect to the database in Visual Basic -


i have following code:

    dim string_conectare string = "data source=|datadirectory|\database1.sdf"     dim conexiune sqlconnection     conexiune = new sqlconnection(string_conectare)     conexiune.open()      if conexiune.state = connectionstate.open         msgbox("ok")     else         msgbox("not ok")     end if 

as can see open connection database every time want test error:

a network-related or instance-specific error occurred while establishing  connection sql server. server not found or not accessible.  verify instance name correct , sql server  configured allow remote connections. (provider: sql network interfaces,  error: 26 - error locating server/instance specified) 

i struggled more 2 hours, please me!

later edit:

i've tried this:

 dim string_conectare string = "provider=microsoft.jet.oledb.4.0;data source=|datadirectory|\database1.sdf;persist security info=true"     dim conexiune oledbconnection     conexiune = new oledbconnection(string_conectare)     conexiune.open()      if conexiune.state = connectionstate.open         msgbox("ok")     else         msgbox("not ok")     end if 

but throw me error:

   unrecognized database format 

here excerpt of same code use connect databases:

private sub btnlogin_click(byval sender system.object, byval e system.eventargs) handles btnlogin.click     dim conn mysqlconnection      'connect database using these credentials     conn = new mysqlconnection     conn.connectionstring = "server=your server site (generally long url); user id=login id mysql user; password=self explanatory; database=name of db you're trying reach"      'try , connect (conn.open)     try         conn.open()      catch myerror mysqlexception 'if fails this... (i.e. no internet connection, etc.)         msgbox("error connecting database. check internet connection.", msgboxstyle.critical)     end try       'mysql query (where call information)     dim myadapter new mysqldataadapter      'tell find file emails/passes stored     dim sqlquery = "select * database selected above email = '" & txtemail.text & "' , password = '" & txtpassword.text & "'"     dim mycommand new mysqlcommand     mycommand.connection = conn     mycommand.commandtext = sqlquery      'start query     myadapter.selectcommand = mycommand     dim mydata mysqldatareader     mydata = mycommand.executereader      if mydata.hasrows = 0         msgbox("invalid email address or password.", msgboxstyle.critical)      else         msgbox("logged in " & txtemail.text & ".", msgboxstyle.information)          me.close()      end if  end sub 

try that.

be sure add resource mysql.data project , call using:

imports mysql.data.mysqlclient 

also! when created database enabled external database access. if don't vb programs not able access , limit access webhost only.


Comments