473,671 Members | 2,305 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 3772
NeoPa
32,569 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,569 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
2298
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 to view its data. " Could anyone show me the steps to configure permission (I tried creating IUSER_DBMACHINE local account on the database box, give this account full permission on the database folder, doesn't work Thank Loc
0
4117
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 have an schema (s1) on an Oracle 9i database with database links pointing to a schema (s2) on another Oracle 9i database.
2
2038
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 Dim tblDef As TableDef Dim strCurrentDatabase As String
2
4977
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 manipulate resident tables using code but not a remote or attached database. Any help you could provide would be greatly appreciated
0
1543
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 the database appears, if I right-click on "Tables", there's no option to add a new table. If I right-click "Servers" in Server Explorer instead and add a new server on my local intranet, I can browse its SQL Server databases, and under each...
3
2283
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 = mysql_connect($db_host, $db_user, $db_password); The browser show this message:
3
2685
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 DBLINK? I hope I was clear. If there are more information that I need to supply, please do tell me. Thank you very much for your replies
0
1090
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
1763
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 driven website - Maintain it via a client application and via the website. As i would like to maintain it both locally and remote via website forms written in ASP, I don't want to sync the information between the server and a client database. I...
1
2954
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 successfully. But when I deployed and executed my Message flow at the point of calling the stored procedure it is giving an excepiton. The exception is "The Procedure is unknown to the database and no definition could be found" But the procedure is...
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8911
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5692
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.