Solved

SQL 6.5 & VB - No ODBC - How to set database?

Posted on 1998-07-22
2
193 Views
Last Modified: 2012-05-05
I'm creating a VB 4.0 application to access data on an SQL server 6.5 database.  I'm not using ODBC, but an .ini file instead.  My last stumbling block (I hope!) is how to set the database parameter so that I can create a recordset with the results of my query.

Below is what PREVIOUSLY set the database for me (when the data was on Sybase, and we used ODBC):
    connect_string = "ODBC;DSN=APPLE;DATABASE=SEED1;"
    Set db = OpenDatabase("APPLE", False, False, connect_string)

The following code is what NOW sets the connection to the database, but it doesn't set the actual database object:
    SqlConn& = SqlOpenConnection(ServerName$, User$, Pwd$, "", "")


I know I'm connecting to the server and database successfully, but just can't seem to set the database parameter.  This is killing me because when I go to run the query against the database, I can't create the recordset without the database object as a reference (see below):
     Set gSrchSet = db.OpenRecordset(gSrchStr, dbReadOnly)

It doesn't know what 'db' is.  

Please help me!  I've been going crazy on this for weeks!  Huge appreciation to anyone who can help!  Thanks so much!
0
Comment
Question by:BooH
2 Comments
 
LVL 1

Accepted Solution

by:
wizard2072098 earned 70 total points
ID: 1466443
After executing the SqlOpenConnection command, execute the SqlUse command to change the database context, as such:

Results% = SqlUse(SqlConn&, "pubs")

That code changes the database context from the master to the pubs database.

Then it's just a matter of executing SqlCmd() and SqlExec() commands, along with SqlNextRow(), etc. to get the data out of the recordset.
0
 
LVL 2

Expert Comment

by:telebasics
ID: 4878359
Where the *&^ do those commands come from? my VB doesn;t know them and i can't find a control that does. Please tell me
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now