Solved

How to connect VB to ODBC ( SQL Server ) ?

Posted on 1998-05-01
2
223 Views
Last Modified: 2012-05-04
How can I write a VB 5 application that can connect to a SQL Server ?
( I already know the steps for adding SQL Server to ODBC )
Can I just directly use a data control to connect the SQL Server ?

Thanks a lot
0
Comment
Question by:stanleylcm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
jcastr earned 50 total points
ID: 1436632
Better connect directly to ODBC  SQL Server DataSource.
To do this in VB5 just follow this

1. In References check DAO 2.5/3.5
2. Create in a Module

Public DB as Database
Public Rs as Recordset


Function OpenDB () as boolean
On error goto ErrHandler

    OpenDB = false
     Set DB = OpenDatabase("MSSQL", false,false,"ODBC;DSN=MSSQL;DATABASE=MyDB;UID=sa;PWD=;")

    OpenDB = True

Out:
     exit sub

ErrHandler:
      Msgbox Error,vbInformation
      Resume Out

end function


now you can execute directly SQL Commands if your OpenDB was successful, try with

if you're querying data

Set Rs = DB.OpenRecordset (SQL, dbOpenTable,dbSQLPAssthrough)

if you are using SQL DDL/DML

DB.Execute SQL, dbSQLPAssthrough
0
 

Expert Comment

by:BogdanGrama
ID: 2802333
You can put this in a module

Public Function fConnectSQL(ByVal sqldsn As String, ByVal sqluser As String, ByVal sqlpass As String) As Boolean
        fConnectSQL = True
        Err = 0
        'La connessione con la SQL Server
        Set connserv = New ADODB.Connection
        connserv.ConnectionString = "DSN=" & sqldsn & ";UID=" & sqluser & ";PWD=" & sqlpass
        connserv.Open
        If Err <> 0 Then
            fConnectSQL = False
            Set connserv = Nothing
        End If
End Function

Send a note if it works
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question