Results 1 to 13 of 13

Thread: Unable to connect to SQL Server 2005

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    82

    Post Unable to connect to SQL Server 2005

    Hy people, I am using VB 6.0 and I am trying to connect to an SQL Server 2005 database but when running my application I get the following error:

    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

    and my code is:

    Dim ConnStr As String
    Dim db As New ADODB.Connection
    Dim rss As New ADODB.Recordset
    Dim sql As String

    sql = "Select * from table"
    ConnStr = "SQLNCLI; Server=ServerIP\SQLEXPRESS; Database=DatabaseName;Uid=usernname;Pwd=Password;"

    db.Open ConnStr
    rs.CursorLocation = adUseClient
    rs.Open sql, db, adOpenDynamic, adLockPessimistic


    Can anyone help me, pleaseeeeeeeeeeeeeee???

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Unable to connect to SQL Server 2005

    Where did you get that connection string?

    With VB6 I do not think you can use SQLNCLI

    With our vb6 code we connect with:

    Code:
        If strDriver = "" Then
            strDriver = "SQLOLEDB"
        End If
        
        'Create a connection to the database
        Set gCn = New ADODB.Connection
        
        gCn.Provider = strDriver
        gCn.Properties("Data Source").Value = strServer
        gCn.Properties("Initial Catalog").Value = strDatabase
        If gstrUser <> "" Then
            gCn.Properties("User Id").Value = gstrUser
            gCn.Properties("Password").Value = gstrPassWord
        Else
            gCn.Properties("Integrated Security").Value = "SSPI"
        End If
        
        gCn.CommandTimeout = 300
        gCn.Open
    We build our string with property values - but you should get the basic idea...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Unable to connect to SQL Server 2005

    You can use it with VB6, you just need to use a valid connection string.

    A connection string is a series of name/value pairs, and in the case of SQLNCLI you provided the value, but not the name to go with it. It should be like this:
    Code:
    ConnStr = "Provider=SQLNCLI; Server=ServerIP\SQLEXPRESS; Database=DatabaseName;Uid=usernname;Pwd=Password;"

  4. #4
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Unable to connect to SQL Server 2005

    Quote Originally Posted by si_the_geek
    You can use it with VB6, you just need to use a valid connection string.
    Si - I didn't know that...

    Is there a benefit to changing the driver?

    Does any of the other ADO code being used need to change??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Unable to connect to SQL Server 2005

    The benefit is that you can use the extra features that it provides (I'm not actually sure what they are!).

    I haven't used it much, but haven't noticed anything that needs changes, which is what I expected (as it is basically an extended version of the OLEDB provider).

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Unable to connect to SQL Server 2005

    And it would need to be installed on client PC's - right? Does it come along with the .Net framework?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Unable to connect to SQL Server 2005

    It does need to be installed, which is perhaps a reason to not use it (certainly if you aren't getting any benefits from it). From what I remember, SQLOLEDB is included MDAC, which of course you also still need to install.

    I have no idea if it is included with the .Net framework, but the redistributable package can be found here (added to the SQL Server 2005 sticky).

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Unable to connect to SQL Server 2005

    Thanks!

    That's a nice link - lots of interesting downloads.

    Wish I had more time to just play with functionality...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2007
    Posts
    82

    SQL Server does not exist or access denied

    Hello everyone. I am using Vb6 to build a aplication that is using a SQL Server 2005 database and my code is listed below:

    If strDriver = "" Then
    strDriver = "SQLOLEDB"
    End If

    'Create a connection to the database
    Set gCn = New ADODB.Connection

    gCn.Provider = strDriver
    gCn.Properties("Data Source").Value = strServer
    gCn.Properties("Initial Catalog").Value = strDatabase
    If gstrUser <> "" Then
    gCn.Properties("User Id").Value = gstrUser
    gCn.Properties("Password").Value = gstrPassWord
    Else
    gCn.Properties("Integrated Security").Value = "SSPI"
    End If

    gCn.CommandTimeout = 300
    gCn.Open

    when trying to connect I get the following error:

    [DBNETLIB][ConnectionOpen(Connect()).] SQL Server does not exist or access denied



    Cound someone help me?

  10. #10
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: SQL Server does not exist or access denied

    I've not used the Properties collection in that way, always just set the connection string as a whole, however my first port of call would be to get a working connection outside of your code.

    See here for creating a UDL file to test a connection and read what the correct values for the parts of your connection should be: http://www.vbforums.com/showthread.p...&highlight=udl

    This stage will also highlight if you have port / firewall / protocal issues which are blocking your connection. Once you have that working, check the values from this file's text match what you're getting in your code by stepping through and debugging the code from a breakpoint...

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  11. #11
    Hyperactive Member
    Join Date
    Jan 2008
    Location
    Merseyside
    Posts
    456

    Re: SQL Server does not exist or access denied

    Using the SQL Management Studio you should be able to create another connection where you can test the connection info you are passing to your app.

    This could be used a quick connection test.
    Last edited by kevchadders; May 12th, 2008 at 05:59 AM.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Unable to connect to SQL Server 2005

    Duplicate threads merged

  13. #13
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Unable to connect to SQL Server 2005

    Is this SQL database on the local workstation or is that a remote ip address?

    If it's remote - then go to that machine and go into MS SQL Server Surface Configuration Utility and make sure that REMOTE CONNECTIONS option is turned on.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

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



Click Here to Expand Forum to Full Width