首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用OleDb从Access窗体连接到SQL Sever

使用OleDb从Access窗体连接到SQL Sever
EN

Stack Overflow用户
提问于 2017-03-07 23:30:42
回答 1查看 41关注 0票数 0

我正在进行一个将Microsoft access后端迁移到SQL Server后端的项目,而我的客户坚持使用Access创建表单来执行任何插入、更新和删除操作。问题是他的机器上有SQL数据工具,他的团队中的其他人(没有数据工具)也需要能够使用这些表单。我认为最好的办法就是通过access使用和OleDb连接来连接到表单,这样他的团队就可以使用它,而我的访问知识非常有限。到目前为止,我只知道下面的内容

代码语言:javascript
运行
复制
“Driver=SQLOLEDB;Data Source=SomeServer;Initial Catalog=SomeDatabase;Integrated Security=SSPI”

我知道用户在SQL机器上有凭证,可以通过ODBC连接。我们只是遇到了让OleDb工作的问题。任何有关如何在access窗体中部署OleDB连接的帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2017-03-07 23:44:43

这是我们用于SQL Server的连接。它支持使用可信连接或SQL Server身份验证。

代码语言:javascript
运行
复制
Call GetConnection(gvstr_SQLServer_Name, gvstr_SQLServer_Database, _
        cnConn, adUseServer, False, False)

    If GetConnection(gvstr_SQLServer_Name, gvstr_SQLServer_Database, _
            gv_DBS_SQLServer, adUseServer, True, False) = True Then
        gvbln_UsingSQLServer = True
        DoCmd.Hourglass True
        ReLink_SQLSERVER_Tables
    Else
        gvbln_UsingSQLServer = False
    End If



Public Function GetConnection(ByVal strDSN As String, _
    ByVal strDatabase As String, _
    ByRef cnLocal As ADODB.Connection, _
    ByVal CursorLoc As CursorLocationEnum, _
    ByVal UsePassword As Boolean, _
    ByVal blnTrusted As Boolean) As Boolean

Dim intWaitDuration     As Integer
Dim strConnectString    As String
Dim strDisplay          As String

Const CURRENT_METHOD As String = "GetConnection"
On Error GoTo ERROR_HANDLER
GetConnection = False
intWaitDuration = 60     
Retry_Connection:
If cnLocal Is Nothing Then Set cnLocal = New ADODB.Connection
If cnLocal.State = adStateOpen Then
        Write_To_Log "Connection already open -- -will not reopen!!"
    GetConnection = True
    GoTo Proc_Exit
End If

With cnLocal
    Debug.Print "Use TRUSTED CONNECTION (ABOVE)"
    If gvstr_Workstation = "my-pc" Then
        strConnectString = "Driver={SQL Server};" & _
                                "Server=" & strDSN & ";" & _
                                "Database=" & strDatabase & ";" & _
                                "Trusted_Connection=yes"
    Else
        If blnTrusted = True Then
            strConnectString = "Driver={SQL Server};" & _
                                "Server=" & strDSN & ";" & _
                                "Database=" & strDatabase & ";" & _
                                "Trusted_Connection=yes"
        Else
             strConnectString = "Driver={SQL Server};" & _
                                "Server=" & strDSN & ";" & _
                                "Database=" & strDatabase & ";" & _
                                "User Id=Sql_myuid;Password=ppppp"

            strDisplay = "Driver={SQL Server};" & _
                                "Server=" & strDSN & ";" & _
                                "Database=" & strDatabase & ";" & _
                                "User Id=S*********t;Password=****************"

        End If
    End If
     Write_To_Log "Will use Conn String: " & strDisplay
    .ConnectionString = strConnectString
    .CursorLocation = CursorLoc
    .Open
End With
GetConnection = True
Proc_Exit:
Exit Function

ERROR_HANDLER:
Debug.Print Err.Number & vbCrLf & Err.Description

Err.Source = "Module_Utilities: GetConnection  at Line: " & Erl
DocAndShowError
Resume Proc_Exit
Resume Next
Resume
End Function
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42652186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档