如何从Visual Basic 6连接到Sql Server 2008数据库?

时间:2011-10-08 10:03:18

标签: sql-server sql-server-2008 connection-string

什么是正确的连接字符串以及从Visual Basic 6连接到Sql Server 2008数据库的要求是什么?

3 个答案:

答案 0 :(得分:2)

您将使用ADODB。这里有一些connection string samples

答案 1 :(得分:2)

' Initialize variables.
Dim cn As New ADODB.Connection
Dim provStr As String

' Specify the OLE DB provider.
cn.Provider = "sqloledb"

' Specify connection string on Open method.
ProvStr = "Server=MyServer;Database=northwind;Trusted_Connection=yes"
cn.Open provStr

仅供参考(Ref。):

Set rsOrders = New Recordset
rsOrders.Open "Select * from orders", cn
Do While Not rsOrders.EOF
    '
    ' If the order matches some custom business logic then get the details for
    ' that order, without opening a new connection.
    '
    If SomeBusinessLogic(rsOrders("CustomerID")) Then
        Dim rsDetails As Recordset
        Set rsDetails = New Recordset
        '
        ' Open a new recordset using the same connection. Normally it's not
        ' possible to have two recordsets simultaniously using the same
        ' connection, but MARS makes this possible
        '
        rsDetails.Open "Select sum(quantity * unitprice) as total " & _
            "from [order details] " & _
            "where OrderID=" & rsOrders("OrderID"), _
            cn
        grandTotal = grandTotal + rsDetails("total")
    End If
    rsOrders.MoveNext
Loop

lblTotalOrders = grandTotal

答案 2 :(得分:2)

Public Cnn As New ADODB.Connection
Cnn.Open Provider=SQLNCLI10;Server=10.1.100.1;Database=DataJualLama;Uid=sa;Pwd=sa;

需要从microsoft站点安装sql server 2008本机客户端运行时。