本文介绍了使用已部署的应用程序进行数据库访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码将审计跟踪信息插入中央数据库,并在开发PC或应用程序服务器上正常工作.
但是,当(部署到另一台PC上)它无法连接/更新数据库.
该代码位于应用程序引用的单独的.dll中.
文件共享和数据库没有限制(域用户具有完全访问权限),DLL在应用程序中被引用,并在安装过程中部署到w应用程序目录中. var ProjectRef也被传递.

有什么想法吗?

我的代码如下:

The following code inserts audit trail information into a central database and works just fine on the dev PC or the application server.
However when deployed (to another PC) it fails to connect / update the database.
The code is in a seprate .dll which is referenced for the app.
The file share and DB have no restrictions (full access for domain users), the DLL is referenced in the app and deployed into thew application dir during setup. The var ProjectRef is passed as well.

Any ideas??

My code below:

Public Class SecIntec
    Dim Username As String
    Dim ComputerName As String
    Dim AccessTime As DateTime
    Dim AppName As String
    Dim DomainName As String
    Dim ProjectRef As String

    'Define database tables and headings 
    Dim Update As String = _
    "INSERT INTO [ApplicationLogging] (AccessDate, UserName, ComputerName, DomainName, AppName, ProjectRef ) Values(?,?,?,?,?,?)"

    'Defind database connection string
    Dim cnnString As String = _
    "Provider = Microsoft.ACE.OLEDB.12.0; Data Source = \\appserver\AppLogs\Database.accdb; "


    Public Sub _DomCK(ByVal ProjectRef As String)

        'Collect the data from the system
        Username = System.Security.Principal.WindowsIdentity.GetCurrent.Name
        DomainName = Environment.UserDomainName
        ComputerName = Environment.MachineName
        AccessTime = Date.Today
        AppName = My.Application.Info.AssemblyName

        ' Check if the domain is correct
        If DomainName = "ThisDomain" Then

            'Try to open and update the database
            Try

                Using cnn As New OleDbConnection(cnnString)
                    cnn.Open()

                    Using cmd As New OleDbCommand(Update, cnn)
                        cmd.Parameters.AddWithValue("AccessDate", AccessTime)
                        cmd.Parameters.AddWithValue("UserName", Username)
                        cmd.Parameters.AddWithValue("ComputerName", ComputerName)
                        cmd.Parameters.AddWithValue("DomainName", DomainName)
                        cmd.Parameters.AddWithValue("AppName", AppName)
                        cmd.Parameters.AddWithValue("ProjectRef", ProjectRef)
                        cmd.ExecuteNonQuery()
                        cnn.Close()
                        cnn.Dispose()

                    End Using

                End Using

            Catch ex As Exception
                'Unable to find or update the database
                Err.Number = 2
                Call ErrorCodeHandle()

            End Try

        Else
            'The Domain is incorrect
            Err.Number = 1
            Call ErrorCodeHandle()

        End If


    End Sub

    Private Sub ErrorCodeHandle()
        Select Case Err.Number 'Evaluate the error number.
            Case 1 'Incorrect domain
                MsgBox("You are not Authorised to use this application...........")
                MsgBox("Please contact [email protected] for assistance")
                MsgBox("This application will now terminate.")
                Call endgame()

            Case (2) 'Unable to locate database file
                MsgBox("Unable to locate a required file (Error 6565)")
                MsgBox("Please contact [email protected] for assistance")
                MsgBox("This application will now terminate.")
                Call endgame()

            Case (3) 'Creation of log file error handler - not currently used
                MsgBox("There was a problem writing to the log file. please try again and if the error persists please contact [email protected] for assistance.")

        End Select

    End Sub

    Private Sub endgame() ' Terminates the calling appication or process

        Dim AppID As Process = Process.GetCurrentProcess()

        ' Kill the calling procedure
        AppID.Kill()

        'Clean up any open or locked file or connections
        AppID.Dispose()

    End Sub



End Class

推荐答案


这篇关于使用已部署的应用程序进行数据库访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 22:19