[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to connect VB to ODBC ( SQL Server ) ?

Posted on 1998-05-01
2
Medium Priority
?
231 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
2 Comments
 
LVL 1

Accepted Solution

by:
jcastr earned 100 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

873 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