function CheckSQLServerConnection () on error resume nextdim conn as new adodb.connection conn.open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=<User ID>;Initial Catalog=pubs;Data Source=<YourDataSourceName>;Network Library=dbnmpntw"if err<>0 then msgbox "连接 SQL SERVER 失败,原因如下:" & err.description else conn.close end ifend function
on error resume nextdim conn as new adodb.connection
conn.open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=<User ID>;Initial Catalog=pubs;Data Source=<YourDataSourceName>;Network Library=dbnmpntw"if err<>0 then
msgbox "连接 SQL SERVER 失败,原因如下:" & err.description
else
conn.close
end ifend function