DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Err: Connection Failed (SQL Server)

  1. #1
    Syrus Guest

    Err: Connection Failed (SQL Server)


    Hi All !!!
    I am using the following code to get connected to the SQL server but getting
    the error :

    '******************************************

    Option Explicit

    Dim conn As ADODB.Connection
    Dim SQL As String

    Private Sub Form_Load()
    Set conn = New ADODB.Connection
    conn.ConnectionString = "Provider=SQLOLEDB.1;Persist " _
    & "Security Info=False;User ID=id;Password=password;" _
    & "Initial Catalog=pubs;Data Source=MAINSERVER"
    SQL = "SELECT * FROM AUTHORS"
    End Sub

    Private Sub Command1_Click()
    conn.Open
    If conn.State = adOpenState Then
    MsgBox "Connection successfull"
    Else
    MsgBox "Connection Failed" '<----I get this mesg
    End If
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    Set conn = Nothing
    End Sub

    *************************************8

    When ever i click Command1 to test the connection I got the message "connection
    failed"

    However with the same ConnectionString ADODC1 Control is working successfully.

    Help me!!
    Any Help Will be apprieciated.
    Syrus

  2. #2
    Alex Guest

    Re: Err: Connection Failed (SQL Server)


    Hi Syrus!
    i'd my bunch of problem with SQL-Server!
    But now it's work fine for all my connection with this code take from the
    MSDN (you may check on the web (msdn.microsoft.com) if you don't have the
    MSDN):

    Dim cnn1 As ADODB.Connection
    ' Open a connection using the Microsoft ODBC provider.
    Set cnn1 = New ADODB.Connection
    ConSQL.ConnectionString = _
    "driver={SQL Server};server=MyServer;database=pubs"
    ConSQL.Open

    I must said that i use the NT Authentication.
    I hope it's will help you!
    good luck!
    Alex.




    "Syrus" <sanjivus@aol.com> wrote:
    >
    >Hi All !!!
    > I am using the following code to get connected to the SQL server but getting
    >the error :
    >
    >'******************************************
    >
    >Option Explicit
    >
    >Dim conn As ADODB.Connection
    >Dim SQL As String
    >
    >Private Sub Form_Load()
    > Set conn = New ADODB.Connection
    > conn.ConnectionString = "Provider=SQLOLEDB.1;Persist " _
    > & "Security Info=False;User ID=id;Password=password;" _
    > & "Initial Catalog=pubs;Data Source=MAINSERVER"
    > SQL = "SELECT * FROM AUTHORS"
    >End Sub
    >
    >Private Sub Command1_Click()
    > conn.Open
    > If conn.State = adOpenState Then
    > MsgBox "Connection successfull"
    > Else
    > MsgBox "Connection Failed" '<----I get this mesg
    > End If
    >End Sub
    >
    >Private Sub Form_Unload(Cancel As Integer)
    > Set conn = Nothing
    >End Sub
    >
    >*************************************8
    >
    >When ever i click Command1 to test the connection I got the message "connection
    >failed"
    >
    >However with the same ConnectionString ADODC1 Control is working successfully.
    >
    >Help me!!
    >Any Help Will be apprieciated.
    >Syrus



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center