Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "Driver={MySQL ODBC 8.0 Unicode Driver};
Server=myServerAddress;
Database=myDataBase;
User=myUsername;
Password=myPassword;
Option=3;"
注:驱动名称、服务器地址、数据库名称、用户名和密码应根据实际情况修改。
示例:
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.ConnectionString = "Driver={SQL Server};Server=myServerName\myInstanceName;
Database=myDataBase;Uid=myUsername;Pwd=myPassword;"
Provider=SQLOLEDB.1;Password=xxxxxx;Persist Security Info=True;User ID=yy;Initial Catalog=zzzz;Data Source=wwwwww 上述字符连接了SQL Server数据库,并且通过用户名和密码来验证访问权限。 若要使用Windows身份验证而不是用户名密码,则无需包括'用户ID”和'密码”参数,而只需使用'Integrated Security = True”或'Trusted_Connection = Yes”来代替。