尝试从Web表单连接到DB2时出错

时间:2018-10-10 14:00:09

标签: db2

简而言之,我们很难从在asp.net/MVC5中开发的Web应用程序连接到DB2。这些驻留在Windows 2013服务器上。以前,在我们较旧的2003服务器上,一切正常。

  1. 我的DSN已在本地计算机上正确设置并成功测试。

  2. 我已经将非常简单的JDBC连接附加到DB2,我们将其放在简单的Web表单上以进行测试。失败并显示以下错误

Error Message

  1. 这是我们正在测试的代码。一个非常简单的连接。

    导入System.Data.OleDb

公开课表格1     私有子Form1_Load(作为对象发送,作为EventArgs发送)处理MyBase.Load         昏暗的strMsg作为字符串

    Dim dbDb2Conn As New System.Data.Odbc.OdbcConnection
    Dim user1 As String = "USER"
    Dim pwd1 As String = "PWD"

    dbDb2Conn.ConnectionString = ("DSN=DB2Profile; uid=" & user1 & "; pwd=" & pwd1 & ";")

    'Oleddb Connection works only with MS SQL Server and Ms. Access.

    'To connect with DB2 You must use ODBC Drivers and ODDBC     Connection.

    ' You have to have Client DB2 installed on Your client machine; This soft generates ODBC drivers

    ' for DB2 connections. 

    'Client DB@ you have to get from IBM

    ' DSN name must be You have previously declared in system ODBC sources as System DSN; in this case DSN name is RYS

    ' username and password you have to get from textboxes of Your Login Form and must be username And pwd of the DB2 user. 

    Try

        dbDb2Conn.Open()



    Catch ex As Exception

        MessageBox.Show(ex.Message)

    Finally

        If dbDb2Conn.State = ConnectionState.Open Then

            ' in case of success

            strMsg = MsgBox("Connection sucessfully open.", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Info")

            Form2.ShowDialog()



        ElseIf dbDb2Conn.State = ConnectionState.Closed Then

            ' in case of case of fail

            ' You make undertake any action You want; this below closes the application

            strMsg = MsgBox("User name or password incorrect.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Warning")

            End

        End If

    End Try

    ' This sample is from VB2008 and working 

    ' In 2005 version should also work.

    ' Remember that this sub is only for CONNECTION open

    ' to get data from the table You have to make command object I write other procedure


End Sub

结束班级

尽管这是一个Web表单(仅用于测试),但我们的MVC5应用程序也存在相同的问题。当我测试本地DSN时,它成功。但是,尝试在本地和IIS上从表单/应用程序内部从DB2连接失败。

任何建议将不胜感激。

0 个答案:

没有答案