远程连接sql server的问题?
我用odbc配置好远程数据库以后,通过adodc控件直接连的odbc中的数据库可以通的,直接通过下面的代码也能连接远程数据库sql server2000:
Set cnn = New ADODB.Connection
cnn.Open "Provider=SQLOLEDB;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=software;Data Source=192.168.1.2 "
其中192.168.1.2就是远程服务器地址。我现在想通过本机配置的odbc来连数据库,就是ado直接连odbc,这样我在odbc中配置好数据库,就不用改程序中的ip地址了,因为有可能ip地址会改变,一旦ip改变,我只要改客户机的odbc中的ip地址好了,不用改程序中的ip地址了。请各位赐教!
比如我看到有人用ado连接odbc
set cnn=New ADODB.Connection
cnn.Open "PROVIDER=MSDASQL;DRIVER={SQLServer};SERVER=????;DATABASE=software;UID=sa;PWD= "我就不知道这里server填什么,是我odbc取的名字吗?
[解决办法]
在外部环境(如注册表)中保存SQL所在的计算机名或IP地址,连接时从外部环境中读取此值
[解决办法]
连接SQL SERVER的几种常见方法
-------------------------------
1.使用ODBC DSN连接字符串
DSN=mySystemDSN;Uid=myUsername;Pwd=myPassword
----------------------------------------------
2.使用无ODBC DSN的连接字符串
(1)标准安全性
Driver={SQL Server};Server=MyServerName;DataBase=myDatabaseName; _
Uid=myUsername;Pwd=myPassword
------------------------------------------------
(2)信任连接(分两种)
1)连接字符串1
Driver={SQL Server};Server=MyServerName;DataBase=myDatabaseName;Uid=;Pwd=;
2)连接字符串2
Driver={SQL Server};Server=MyServerName;DataBase=myDatabaseName;Trusted_Connection=yes
---------------------------------------
(3)连接本地SQL SERVER
Driver={SQL Server};Server=(local);DataBase=myDatabaseName; _
Uid=myUsername;Pwd=myPassword
-------------------------
(4)连接远程SQL SERVER
Driver={SQL Server};Server=xxx.xxx.xxx.xxx; _
Address=xxx.xxx.xxx.xxx,1433; _
Network=DBMMSOCN;DataBase=myDatabaseName; _
Uid=myUsername;Pwd=myPassword
-------------------------------------------------------
3.使用OLEDB PROVIDER FOR SQL SERVER的连接字符串
(1)标准安全性
Provider=SQLOLEDB.1; _
Password=myPassword; _
User ID=myUsername; _
Initial Catalog=myDatabaseName; _
Data Source=MyServerName
-------------------------------------------
(2)信任连接
Provider=SQLOLEDB.1; _
Initial Catalog=myDatabaseName; _
Data Source=MyServerName; _
Integrated Security=SSPI
--------------------------------------
(3)连接到命名实例
Provider=SQLOLEDB.1; _
Initial Catalog=myDatabaseName; _
Data Source=myServerName\myInstanceName; _
Password=myPassword; _
User ID=myUsername
--------------------------------------
(4)连接到本地SQL SERVER
Provider=SQLOLEDB.1; _
Password=myPassword; _
User ID=myUsername; _
Initial Catalog=myDatabaseName; _
Data Source=(local)
-----------------------------------------
(5)连接到远程SQL SERVER
Provider=SQLOLEDB.1; _
Netwprk Library=DBMMSOCN; _
Data Source=xxx.xxx.xxx.xxx,1433; _
Password=myPassword; _
User ID=myUsername; _
Initial Catalog=myDatabaseName;