DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Connection String to SQL Server

  1. #1
    Join Date
    Jul 2004
    Posts
    143

    Connection String to SQL Server

    What is the best method to connect to a SQL Server database from another PC using VB6? Do I have to create an ODBC connection or can I qualify the server name in with the rest of the connection string? Can someone give me an example of both. I am moving from the Access world to SQL Server. I use SQL statements to hit Access so my hurdle is the connection string.
    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    Huddinge, Sweden
    Posts
    283
    If you're using ADO it's best to use the native SQL Server OLDEB provider:
    "server=myserver;database=mydatabase;integrated security=yes"

    I have never (to the best of my memory) used the ODBC drivers to get at SQL Server from VB6, and I can't really see a reason why.

    Rune
    If you hit a brick wall, you didn't jump high enough!

  3. #3
    Join Date
    Jul 2004
    Posts
    143
    Thanks
    I did the following and it seems to connect (I get no errors). Now I have to figure out the SELECT...

    Dim cnn As New ADODB.Connection
    Dim strConnect As String, strSQL As String
    strConnect = "Provider=SQLOLEDB;Data Source=ST01;Initial Catalog=MyDatabase;User Id=myuserid;Password=mypass;"
    cnn.Open strConnect
    'SELECT
    cnn.Close

  4. #4
    Join Date
    Apr 2004
    Posts
    59
    to find out any connection string go to
    www.connstr.com
    hope it would be helpfull to u

    Humair

  5. #5
    Join Date
    Dec 2003
    Posts
    2,750
    Code:
    Dim rs As New ADODB.Recordset
    rs.Open "SELECT * FROM Customers", cnn, adOpenStatic, adLockOptimistic
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  6. #6
    Join Date
    Aug 2006
    Posts
    1

    connect sql server with vb6

    Dim cn1 As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    cn1.Open ("provider=MSDASQL.1;" & "extended properties=DSN=sam;UID=sam;PWD=123456;DATABASE=data;persist security info=false")
    If rs.State <> ADODB.ObjectStateEnum.adStateClosed Then
    rs.Close
    End If
    rs.CursorLocation = adUseClient
    rs.Open "select * from mat", cn1, adOpenStatic, adLockBatchOptimistic, ADODB.CommandTypeEnum.adCmdText

    'dsn =sam to specify the odbc name


    i think its ok to connect sqlserver with vb6.

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