473,511 Members | 16,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA switch from local to remote database

3 New Member
I am using a local 2010 Access Database linked to a MySQL Database using ODBC Driver 5.1.

I want to easily switch from local linked tables on my development PC to a local network database.

The server string localhost or 127.0.0.1 works fine but when changed to 192.168.xxx.xxx then I receive the message

Run-time error '3146'
ODBC --call failed



Expand|Select|Wrap|Line Numbers
  1. Function relinkTables(server As String)
  2. Dim db As DAO.database
  3. Dim tdf As DAO.TableDef
  4. Dim constring, strconnect, port, user, password, database As String
  5.  
  6. Set db = CurrentDb
  7.  
  8. port = "3306"
  9. user = "myuser"
  10. password = "mypassword"
  11. database = "mydatabase"
  12.  
  13. strconnect = "ODBC;DRIVER={MySQl ODBC 5.1 Driver};" & _
  14.                           "SERVER=" & server & ";" & _
  15.                           "PORT=" & port & ";" & _
  16.                           "DATABASE=" & database & ";" & _
  17.                           "USER=" & user & ";" & _
  18.                           "PASSWORD=" & password & ";" & _
  19.                           "OPTION=3;"
  20.  
  21.     For Each tdf In CurrentDb.TableDefs
  22.         ' check if table is a linked table
  23.         If Len(tdf.connect) > 0 Then
  24.                tdf.connect = strconnect
  25.              tdf.RefreshLink
  26.         End If
  27.     Next
  28.  
  29. End Function
  30.  
Apr 24 '12 #1
5 3766
NeoPa
32,557 Recognized Expert Moderator MVP
If you set the link up manually and then look at the connection string (.Connect), what does it say in the "SERVER=???;" part?
Apr 25 '12 #2
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Just a quick comment to your code, which isn't really related to the question, but I feel its worth mentioning as its a common mis-conception.

Expand|Select|Wrap|Line Numbers
  1. Dim constring, strconnect, port, user, password, database As String
will declare constring, strconnect, port, user, password as VARIANT
and only database as STRING.

This is a common error as it is not quite obvious that it happens, and its an area where VB.NET syntax differs from VBA.
Apr 25 '12 #3
mikeimp
3 New Member
@NeoPa
If I set up the link using the Access ODBC tool then I have to use a DNS connection. I do not know how to set up a link any other way. The connection prior to tdf.refresh is SERVER=192.168.XXX.XXX; I am nervous about giving out the local IP address of the webserver so have replaced the numbers with X.
Apr 25 '12 #4
mikeimp
3 New Member
@TheSmileyCoder
Thanks for the info much appreciated
Apr 25 '12 #5
NeoPa
32,557 Recognized Expert Moderator MVP
In that case I see nothing wrong with your code. It appears to be handling the situation exactly as you'd want it to. I'm afraid that also means I have no idea why it wouldn't be working.

BTW. 192.168.X.X is a Class B public address range. That means it is not routable on the internet (IE. It is perfectly safe to share publicly as no-one outside of your internal network will be able to connect to it using that address). That said, using XXX is also perfectly ok as far as the question goes. Your meaning is perfectly clear.
Apr 25 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2288
by: Loc | last post by:
I have asp page needs to access remote database, I got error"The Microsoft Jet database engine cannot open the file 'Unknown'. It is already opened exclusively by another user, or you need permission...
0
4102
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
2
2025
by: RWC | last post by:
Hello, I'm trying to do some updates on the fly in a remote database. I'd like to do this with code. I'm running basically the following code; Dim db As Database Dim tblDefs As TableDefs...
2
4958
by: Jozef | last post by:
I'm using Access XP. I'm trying to create a table, modify a table, create in index, and create a relationship in a remote database in code from the program database. I know how to create and...
0
1533
by: Bennett Haselton | last post by:
In Visual Studio .Net 2002 Server Explorer, if I add a new connection under "Data Connections", I can specify a remote server name and the username and password that I want to use, but then when...
3
2274
by: Luca | last post by:
I'have Easy PHP in localhost and i need connect php page (local) to remote database: $db_host = "62.149.225.23"; $db_user = "gfo"; $db_password = "gfo"; $db_name = "gfonline"; $db =...
3
2671
by: Pakna | last post by:
Hello, I have what may be a beginner's question regarding DB2. How does one access a remote table on a remote database via SQL? What is the command string, is there an equivalent of Oracle...
0
1083
by: Samiran Samanta | last post by:
Hi Friends, Can anyone please tell me, How to derive data from a table of the local database and use it to extract data from a remote database. Thanks Samiran
3
1755
by: Nymus | last post by:
I would like to use an access database as a shared database on a remote website. I don't know if it is possible, but this is what i would like to do with this database: - Use it to run a database...
1
2938
by: integraion | last post by:
hi, Iam having a message flow within which iam calling the stored procedure which is remotely maintained. I have connected to the remote database through my DB2 and tested the connection...
0
7245
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7144
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7427
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1577
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.