»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 06-02-2003, 12:55 PM   #1 (permalink)
Registered User
 
highrock's Avatar
 
Join Date: Aug 2002
Location: US
Posts: 138
highrock is on a distinguished road
Kids Connecting to SQL Server 2000 w/ VB6

Anyone know how to connect to SQL Server 2000 using Visual Basic 6?

highrock is offline   Reply With Quote
Old 06-03-2003, 05:58 PM   #2 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
Use ADO
Either via code or the ADO control

If you want more info, you have to be more specific what you want to do...

Check around google with 'ado vb6' and I'm sure you'll get plenty of info
If you have specific questions we'll be here.
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 06-27-2003, 12:02 PM   #3 (permalink)
Registered User
 
highrock's Avatar
 
Join Date: Aug 2002
Location: US
Posts: 138
highrock is on a distinguished road
'form level variables
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset


Private Sub Form_Load()
Dim oConn As ADODB.Connection
Dim oRS As ADODB.Recordset
Set oConn = New ADODB.Connection
Set oRS = New ADODB.Recordset

oConn.Open "Provider=sqloledb;" & _
"Data Source=testcaelus;" & _
"Initial Catalog=cmstest;" & _
"Uid=sa;" & _
"Pwd="

End Sub

-----------
I get an error: -2147467259(80004005)
unspecified error

occurs on the oConn.Open section of code.
highrock is offline   Reply With Quote
Old 06-27-2003, 12:46 PM   #4 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
You haven't initialized the connection object

Easiest way to do it is to dim your objects with New
Dim oConn As New ADODB.Connection

Or before you the open you can put

Set oConn = New ADODB.Connection

Its one or the other, not both
Putting it later can save some resources as it doesn't initilalize it until its required to be used. Otherwise the OS reserves the resources for it right away and it wastes resources until its used.

and yes you'll need to do that for bothof your recordsets as well

The 2nd connection I see you have declared should only be required IF its to a 2nd database. You can have multiple recordsets and command objects on one connection (actually highly suggested)
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>

Last edited by vass0922; 06-27-2003 at 12:49 PM.
vass0922 is offline   Reply With Quote
Old 06-27-2003, 12:57 PM   #5 (permalink)
Registered User
 
omalleytrading's Avatar
 
Join Date: Apr 2003
Location: Albany, NY
Posts: 425
omalleytrading is on a distinguished road
Actually, yes, he did initialize the connection object. It's the 3rd line of the Form_Load

For one thing, you probably shouldn't do anything important in the form load. Put it in the Form Activate, or better yet in a Main subroutine.

For another, it's an EXTREMELY bad idea to have an sa account without a password and to use it in your code. Create a new account with only the permissions needed for your program. Saftely first!

Try this as your connection string:

Const CONNECTION_STRING = "Provider=sqloledb;" & _
"Data Source=testcaelus;" & _
"Initial Catalog=cmstest;" & _
"User Id=sa;" & _
"Password="

I'm not sure if the short-hands for userid and password are acceptable.

Also, it appears as though you're using an ODBC id as the Data Source. I've always used the server name there (sql.myserver.com, for example) -- try that.

If you just want to connect by ODBC, you can use something like:

oConn.Open "DSN=testcaelus;UID=sa;PWD="
omalleytrading is offline   Reply With Quote
Old 06-27-2003, 01:00 PM   #6 (permalink)
Registered User
 
Join Date: Oct 2001
Location: TOO close to Wash DC
Posts: 7,956
vass0922 is on a distinguished road
Whoops
Didn't see that at all

read too fast, thats what I was reading as his 2nd connection object
__________________
<< Insert exceedingly large and overly verbose message of how 1337 you are here including full specs of every vehicle you've ever driven and PC you've owned >>
vass0922 is offline   Reply With Quote
Old 06-27-2003, 02:06 PM   #7 (permalink)
Registered User
 
omalleytrading's Avatar
 
Join Date: Apr 2003
Location: Albany, NY
Posts: 425
omalleytrading is on a distinguished road
Don't worry, Vass -- I didn't see it at first either. I almost clicked away thinking that you had nailed it, but something kept nagging me. Must have seen it subconciously.....
omalleytrading is offline   Reply With Quote
Old 06-27-2003, 02:18 PM   #8 (permalink)
Registered User
 
highrock's Avatar
 
Join Date: Aug 2002
Location: US
Posts: 138
highrock is on a distinguished road
thanks, i'll try it monday time to leave work and relax at home. oh i know the account name is bad but I just need to get a connection to the sql server.
highrock is offline   Reply With Quote
Old 06-30-2003, 07:05 AM   #9 (permalink)
Registered User
 
highrock's Avatar
 
Join Date: Aug 2002
Location: US
Posts: 138
highrock is on a distinguished road
Const CONNECTION_STRING = "Provider=sqloledb;" & _
"Data Source=sql.testcaelus.com;" & _
"Initial Catalog=cmstest;" & _
"User Id=sa;" & _
"Password="
oConn.Open CONNECTION_STRING


I still get same error even with the sql.myserver.com
everything loads up fine until i put in the oConn.Open line.
highrock is offline   Reply With Quote
Old 06-30-2003, 06:31 PM   #10 (permalink)
Registered User
 
Join Date: Sep 2002
Posts: 265
Creosote is on a distinguished road
Wrong Order:

Code:
Dim con1 As New ADODB.Connection
    con1.ConnectionString = "Provider=SQLOLEDB.1;" & _
    "Password=YOUR_PASSWORD;" & _
    "Persist Security Info=True;" & _
    "User ID=sa;" & _
    "Initial Catalog=YOUR_CATALOG;" & _
    "Data Source=YOUR_SERVER_NAME"
BTW, cmstest? not as in casino is it?
Creosote is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 03:51 AM.