dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Hanging while try to get Databases from speified SQL server

  1. #1
    Join Date
    May 2000
    Location
    MI - USA
    Posts
    488

    Hanging while try to get Databases from speified SQL server

    Hi All,

    I am trying to get databases from the SQL server of other machine (not local) that is in my network, then I am getting some errors even after I mentioned the time out as 30. I need the control shoul come back to my application after the time expires (i.e. after 30 seconds). By telling the server is not up or access denied. So that I can display the error message and not populate the databases combo. Please see the code below.

    Code:
    Public Function DBList_Retrieve(ByRef cmbDBList As ComboBox, ByVal sServer As String) As String
        
        Dim cnn As ADODB.Connection
        Dim ars As ADODB.Recordset
        Dim sql As String
        Dim iIndex As Integer
        Dim bFound As Boolean
        
        bFound = False
        iIndex = 0
        cmbDBList.Clear
        Set cnn = New ADODB.Connection
        With cnn
        .Provider = "SQLOLEDB"
        .ConnectionTimeout = 0
        .CursorLocation = adUseClient
        .ConnectionString = "SERVER=" & sServer & ";uid=sa;INITIAL CATALOG=master"
        .Open
        End With
        sql = "select * from sysdatabases"
        Set ars = cnn.Execute(sql)
        Do Until ars.EOF
        cmbDBList.AddItem ars!Name
        If ars!Name = "master" Then
            bFound = True
        End If
        If bFound = False Then
           iIndex = iIndex + 1
        End If
        
        ars.MoveNext
        Loop
        cnn.Close
        DBList_Retrieve = "master"
        cmbDBList.ListIndex = iIndex
        
    End Function
    Please suggest how can I get?

    Thanks,
    Narayana Murty.

  2. #2
    Join Date
    Apr 2000
    Location
    Southampton, UK
    Posts
    329
    The problem is that your connection string is not correct.

    .ConnectionString = "Provider=SQLOLEDB;Data Source=" & sServer & ";Initial Catalog=Master;User ID=sa;Password=xxxx;Persist Security Info=True;"

    Or if using Integrated Security
    .ConnectionString = "Provider=SQLOLEDB;Data Souce=" & sServer & ";Initial Catalog=Master;Integrated Security=SSPI;Persist Security Info=False;"

    Obviously you don't need the first element if you are specifying the .Provider property but I include it for completeness.
    TimCottee
    I know a little about a lot of things and a lot about very little.

    Brainbench MVP For Visual Basic
    http://www.brainbench.com

    MCP, MCSD, MCDBA, CPIM

  3. #3
    Join Date
    May 2000
    Location
    MI - USA
    Posts
    488
    Thanks TimCottee.

    It seems it is working fine.



    Narayana Mutry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)