【发布时间】:2011-10-08 10:03:18
【问题描述】:
什么是正确的连接字符串以及从 Visual Basic 6 连接到 Sql Server 2008 数据库的要求是什么?
【问题讨论】:
标签: sql-server sql-server-2008 connection-string
什么是正确的连接字符串以及从 Visual Basic 6 连接到 Sql Server 2008 数据库的要求是什么?
【问题讨论】:
标签: sql-server sql-server-2008 connection-string
' 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
【讨论】:
您将使用ADODB。这里有一些connection string samples。
【讨论】:
Public Cnn As New ADODB.Connection
Cnn.Open Provider=SQLNCLI10;Server=10.1.100.1;Database=DataJualLama;Uid=sa;Pwd=sa;
需要从微软站点安装sql server 2008 native client runtime。
【讨论】:
{ })工具栏以很好地格式化和语法突出显示它!