asp网页怎样连接SQL数据库

2024-11-30 11:47:43
推荐回答(3个)
回答1:

asp连接数据库的代码为:
Set conn = Server.CreateObject(ADODB.Connection);
conn.Opendriver={SQLServer};server=202.108.32.94;uid=wu77445;pwd=p780522;database=w
ww_panwei_com;conn open其中/Set conn = Server.CreateObject(ADODB.Connection)为设置一个数据库的连接对象
driver=()告诉连接的设备名是SQL-SERVER
server是连接的服务器的ip地址,Uid是指用户的用户名,pwd是指的用户的password,
database是用户数据库在服务器端的数据库的名称

回答2:

Set Conn=Server.CreateObject("ADODB.Connection") Conn.Open "Driver={SQL Server};Server=(local);Database=aaaa;UID=sa;PWD=123;" If Err Then err.Clear Set Conn = Nothing Response.Write("

数据库连接出错,请检查连接字串!
") Response.End end if]

回答3:

连接远程mysql的配置代码如下: Dim cn As New ADODB.Connection '创建数据库对象 Dim rs As New ADODB.Recordset '创建表对象 Dim strCn As String '连接字符串 Dim db_host As String Dim db_user As String Dim db_pass As String Dim db_data As String db_host = "1111.100.123.32" '服务器IP地址 db_user = "admin" 'Mysql数据库 登陆用户名 db_pass = "123456" 'Mysql数据库 登陆密码 db_data = "工资表" '数据库的库名称 strCn = "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=" & db_host & ";" & "DATABASE=" & db_data & ";" & _ "UID=" & db_user & ";PWD=" & db_pass & ";" & "OPTION=3;stmt=SET NAMES GB2312" cn.Open strCn '打开数据库 cn.CursorLocation = adUseClient If cn.State = adStateOpen Then MsgBox "打开远程MySQL数据库成功"当然,你除了上述代码正确以外,本地机器上的ODBC还应该配置正确才行的,否则仍然不能成功连接的。]