【问题标题】:Problems connecting to remote SQL Server using AutoIT使用 AutoIT 连接到远程 SQL Server 时出现问题
【发布时间】:2012-10-05 17:20:03
【问题描述】:

我正在尝试创建一种登录机制,如果凭据正确,您可以通过该机制访问专用网络中的远程 SQL Server 2008 R2 数据库。我打算在我的工作服务器上实现数据库,并在与服务器位于同一子网的客户端上实现这个程序。到目前为止,这是我的代码:

Func Login()

   $loginGUI = GUICreate("Login", 250, 150, -1, -1) ; will create a dialog box that when displayed is centered
   GUISetState(@SW_SHOW)
   GUICtrlCreateLabel ( "Input valid credentials to login", 40, 10,-1,-1) 
   GUICtrlCreateLabel ( "Username", 40, 40,-1,-1)
   Local $userInput = GUICtrlCreateInput("", 100, 37, 100, 20)
   GUICtrlSetState($userInput, $GUI_FOCUS)
   GUICtrlCreateLabel ( "Password", 40, 70,-1,-1)
   Local $passwordInput = GUICtrlCreateInput("", 100, 67, 100, 20, $ES_PASSWORD)
   Local $loginButton = GUICtrlCreateButton("Login", 40, 105, 70)
   Local $exitButton = GUICtrlCreateButton("Exit", 130, 105, 70)

   GUISetState()
   ; Run the GUI until the dialog is closed
   While 1
      $msg = GUIGetMsg(1)
      Switch $msg[0]
         Case $loginButton
            $user = GUICtrlRead($userInput)
            $password = GUICtrlRead($passwordInput)
            Global $loginCon = ObjCreate( "ADODB.Connection" )
            With $loginCon
               .ConnectionString =("DRIVER={SQL Server};SERVER=192.168.1.30\SQLEXPRESS;DATABASE=Test;UID="&$user&";PWD="&$password&";")
               .Open
            EndWith
            If ($user ="" and $password="") or @error Then
               MsgBox(48, "Login error", "Connection failed! Wrong Username/Password.")
               GUICtrlSetData($userInput, "")
               GUICtrlSetData($passwordInput, "")
               GUICtrlSetState($userInput, $GUI_FOCUS)
            Else
               $loginCon.Close
               GUIDelete()
               Main()
               ExitLoop
            EndIf
         Case $exitButton
            GUIDelete()
            ExitLoop
         Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop
      EndSwitch
   WEnd

EndFunc

我还做了以下操作:

  1. 使用 SQL Server Management Studio 允许远程连接以及正确用户访问数据库的适当权限。
  2. 使用 SQL Server 配置管理器启用 SQL Server Browser 和具有适当配置的 TCP/IP 协议以访问服务器。
  3. 创建了防火墙入站和出站规则,允许服务器和客户端访问 TCP 端口 1433 和 UDP 端口 1434(以防万一)。
  4. sqlservr.exesqlbrowser.exe 添加到防火墙允许的程序列表中。
  5. 在客户端 PC 上安装了 SQL Server Native Client 2008 R2。

我可以使用服务器 IP 在本地连接到我的数据库,但在尝试从远程客户端连接到服务器时出现以下错误:

err.description 是:[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server 不存在或访问被拒绝。

奇怪的是,我可以使用sqlcmd 从远程客户端进行连接。我还必须提到,我目前正在使用我的笔记本电脑来保存我的测试数据库。它的 IP 由 DCHP 服务器从工作中分配,并且始终保持不变。

我的代码不正确还是我必须进行额外的服务器/客户端配置?

【问题讨论】:

    标签: sql database sql-server-2008 autoit remote-connection


    【解决方案1】:

    我建议用 autoit 编写客户端和服务器,而不是那样做。将服务器放到远程计算机上,使其与本地数据库交互。比将您想要的东西返回给客户。这种方法也更安全。 Here is where you can start

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 2012-11-25
      • 2021-06-18
      • 1970-01-01
      相关资源
      最近更新 更多