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. 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. Also if you are using SQL Authentication in the connection string, you don't require to provide "Integrated Security = SSPI". and vice versa.
精彩评论