使用vb连接到sql server 2008

时间:2013-07-25 04:39:15

标签: vb.net sql-server-2008 asp-classic

Function DBConnect()
Dim  vConnString, wfConnection, objConn
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open Application("DB_CONNECT")    
set DBConnect = objConn
exit function
Response.Write("connected to Server 2008")
End Function    

Function GetValue()
Dim objCmd, objRS   
Set objCMD = Server.CreateObject("ADODB.Command")
Set objRs = Server.CreateObject("ADODB.Recordset")

With (objCMD) 
    .ActiveConnection = DBConnect()
    .CommandType = adCmdStoredProc
    .CommandText = "select * from Acc.dbo.table"

    set ObjRS = .Execute()    
End With
 if err.number = 0 then
    if not objRs.EOF then
        arrData = objRs.GetRows 

        vDesc = arrData(5,0)
    else
        vDesc = vValue
    end if

    GetDescFromCode = True
end if

响应即将来临

connected to Server 2008

在调试的时候,我知道它不会进入objRs.EOF如果循环......任何想法都错了

1 个答案:

答案 0 :(得分:0)

  1. 在DBConnect中,检查objConn的状态以确保它确实被打开。
  2. 在DBConnect中,exit function之前有response.write
  3. 在GetValue中,检查err.number的值。