[英]VBA ADODB Connection String with Port
I am working on an Excel VBA project where I connect to a MySQL server using ADODB, but I can't figure out how to add the port information to the connection string. 我正在处理一个Excel VBA项目,在该项目中我使用ADODB连接到MySQL服务器,但是我不知道如何将端口信息添加到连接字符串中。 My connection code works as I've connected to other DB's, but I recently moved to my local computer where I have multiple connections with each residing on a different port. 我的连接代码在连接到其他数据库时就可以使用,但是最近我移到了本地计算机上,在那里我有多个连接,每个连接都位于不同的端口上。 Here is my current connection string: 这是我当前的连接字符串:
''''''''''''''''''''''''''''''''''''''''''''''''
' My Laptop Connection
''''''''''''''''''''''''''''''''''''''''''''''''
Public Const server_name As String = "127.0.0.1:5353" 'Enter your server name here - if running from a local computer use 127.0.0.1 or localhost
Public Const database_name As String = "juice" 'Enter your database name here
Public Const user_id As String = "root" 'Enter your user ID here
Public Const password As String = "Password1" 'Enter your password here
Public Const MySQLConnectStr As String = "DRIVER={MySQL ODBC 5.3 ANSI Driver}" _
& ";SERVER=" & server_name _
& ";DATABASE=" & database_name _
& ";UID=" & user_id _
& ";PWD=" & password _
& ";OPTION=16427"
Okay, I figured it out over on connectionstrings.com - http://www.connectionstrings.com/mysql-connector-odbc-5-2/ 好的,我在connectionstrings.com- http://www.connectionstrings.com/mysql-connector-odbc-5-2/上找到了答案
You supply the port in a separate argument. 您在单独的参数中提供端口。 See my fixed code below. 请参阅下面的固定代码。
''''''''''''''''''''''''''''''''''''''''''''''''
' My Laptop Connection
''''''''''''''''''''''''''''''''''''''''''''''''
Public Const server_name As String = "127.0.0.1" 'Enter your server name here - if running from a local computer use 127.0.0.1 or localhost
Public Const database_name As String = "juice" 'Enter your database name here
Public Const user_id As String = "root" 'Enter your user ID here
Public Const password As String = "Password1" 'Enter your password here
Public Const port As String = "5353" 'If a specific port enter here. connection string uses 3306 by default.
Public Const MySQLConnectStr As String = "DRIVER={MySQL ODBC 5.3 ANSI Driver}" _
& ";SERVER=" & server_name _
& ";PORT=" & port _
& ";DATABASE=" & database_name _
& ";UID=" & user_id _
& ";PWD=" & password _
& ";OPTION=16427"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.