How do I connect to an access database on the server if the server is avaliable? and if the server is not avaliable connect to the local access database when the application first starts up.
How do I switch the connection between the local database and the server database when the application has already started.
Thank you.
Loading
Hirendra SisodiyaPosted Mar 19, 2010, 7:37 AM
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\db\access.mdb;user id=sa;Jet OLEDB:Database password=password"
thanks
please mark "Do you like this answer " check box, if you like this answere
Hirendra SisodiyaPosted Mar 26, 2010, 6:06 AM
'hello Tuch
' i check this code on my side and it is going perfectly....ok
' you can also check this line
obj = System.Net.Dns.GetHostByName("ServerName")
' tuch you can use another idea, you can use connction string for validating server and database is exist or not like this code sample:
Try
Dim conn As New OleDb.OleDbConnection("Server oriented Connection string")
conn.open()
Catch ex As Exception
Dim conn As New OleDb.OleDbConnection("Local Connection string")
conn.open()
End Try
thanks
Tuck HohPosted Mar 26, 2010, 3:52 AM
Dim server_Available As Boolean = False
Try
Dim obj As System.Net.IPHostEntry
obj = System.Net.Dns.GetHostEntry("ServerName")
server_Available = True
Catch ex As Exception
server_Available = False
End Try
I tested the line of code with the network connection off on my laptop and it works. But if the network connection is on but the servername does not exist on the network, server_Available returns "true". I tested this even on a different network, without the server but server_Available returns "true"
Tuck HohPosted Mar 20, 2010, 4:00 AM
Thank you
Tuck HohPosted Mar 19, 2010, 6:32 AM
Hirendra SisodiyaPosted Mar 19, 2010, 6:17 AM
'this error means your connection string is wrong, check your database path, userid and password.
'you can use this code
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\db\access.mdb;user id=;password="
con.Open()
thanks
' please mark "Do you like this answer " check box, if you like this answere
Tuck HohPosted Mar 19, 2010, 5:32 AM
Dim con As New OleDb.OleDbConnection
con.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\db\access.mdb;user id=sa;password=password"
I keep getting this error when I issue con.Open()
"Cannot start your application. The workgroup information file is missing or opened exclusively by another user."
How do I get about this?
Hirendra SisodiyaPosted Mar 19, 2010, 12:53 AM
to know server is avaliable or not you can use this code on application start up :
Dim server_Available As Boolean = False
Try
Dim obj As System.Net.IPHostEntry
obj = System.Net.Dns.GetHostEntry("ServerName")
server_Available = True
Catch ex As Exception
server_Available = False
End Try
If server_Available Then
'place you connection string to connect the server access database
Else
'place you connection string to connect the local access database
End If
'You can give option like 'Change Database' through button or any menuitem etc in your application, change your conncton string and restart your application.
thank you
mark as answere if you like my answere