George Trevour Dsouza
George Trevour Dsouza

Reputation: 171

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. 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?

Upvotes: 0

Views: 4892

Answers (2)

vijay pawar
vijay pawar

Reputation: 11

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

Upvotes: 1

Anuraj
Anuraj

Reputation: 19598

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.

Upvotes: 0

Related Questions