简体   繁体   English

VB.NET Windows窗体中的数据库连接

[英]Database Connection in VB.NET Windows Forms

I have a problem with connecting to a server which is another machine. 我连接到另一台服务器的服务器时遇到问题。 When I try connecting to my machine with the following code, it works fine: 当我尝试使用以下代码连接到我的机器时,它可以正常工作:

'connString = "Data Source = .\sqlexpress;" & _  
'"Initial Catalog = one;" & _  
'"Integrated Security = SSPI"  

Try  
  conn = New SqlConnection(connString)  
  conn.Open()  
  MessageBox.Show("Connection Successful")  
Catch ex As Exception  
  MessageBox.Show(ex.Message)  
End Try 

But when I try to get connected to another machine where SQL Server 2000 is installed, I get a timeout message. 但是,当我尝试连接到另一台安装了SQL Server 2000的计算机时,出现了超时消息。 The code is as follows: 代码如下:

connString = "Server = xxx.xxx.xxx.xxx;" & _  
    "Initial Catalog = one;User Id=xxxx; Password=xxxxx;" & _  
    "Integrated Security = SSPI"  

    Try  
      conn = New SqlConnection(connString)  
      conn.Open()  
      MessageBox.Show("Connection Successful")  
    Catch ex As Exception  
      MessageBox.Show(ex.Message)  
    End Try 

Can anyone please help me on this issue? 谁能帮我解决这个问题?

Imports System.IO
Imports System.Data.SqlClient
Public Class Supplier
    Dim scon As New SqlConnection

//you write your code in load event

Private Sub Supplier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        scon = New SqlConnection("your connection string")
        scon.Open()
    End Sub


Endclass

It will be great help if you can provide more information like exception stack trace / code will be helpful. 如果您可以提供更多信息,如异常堆栈跟踪/代码会有所帮助,这将是非常有用的。 Also make sure you are able to connect to the remote server with SQL Management Studio. 另外,请确保您能够使用SQL Management Studio连接到远程服务器。 Also if you are using SQL Authentication in the connection string, you don't require to provide "Integrated Security = SSPI". 另外,如果在连接字符串中使用SQL身份验证,则不需要提供“集成安全性= SSPI”。 and vice versa. 反之亦然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM