Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2004, 10:46 AM
Authorized User
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB4 Connection to SQL2000

Hopefully someone can help me here.

I'm trying to write a small VB4 program that connects to an SQL DB on another machine on the network.
I've managed to get another project (Excel VBA to connect to SQL via ADO) working fine. But cannot get this project to work.

Can anyone help me with some tips/pointers as to any extras/addins required or some code examples to get a connection and maybe even running the SQL.

VB4 doesn't like the code below (this is how it was done with VBA). It says "argument not optional" at the highlighted section. How can it be done with VB4?

Code:
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection

' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB; DATA SOURCE=ops-serv;INITIAL CATALOG=testDB; INTEGRATED SECURITY=sspi;"

'Now open the connection.
cnPubs.Open  strConn
Thanks
 
Old June 4th, 2004, 10:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

i dont know why your code is falling. maybe something with vb4???
all the arguments for open are optionals... and your code looks fine...

can you try something like
Code:
cnpubs.connectionstring = strconn
cnpubs.open

HTH

Gonzalo
 
Old June 4th, 2004, 11:07 AM
Authorized User
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It says "Invalid use of property" for the .ConnectionString section
 
Old June 4th, 2004, 11:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

wich references do you have on the project?? are you sure that are you using ado???

HTH

Gonzalo
 
Old June 5th, 2004, 03:56 AM
Authorized User
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

All the general stuff, plus Standard OLE Types, Microsoft DAO 3.0 Object Library and Microsoft ActiveX Data Objects 2.6 Library
 
Old June 7th, 2004, 05:07 AM
Authorized User
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anyone even know of any other sites they can refer me to? I still have had no success with this. What is it I'm missing?
 
Old June 7th, 2004, 01:05 PM
Authorized User
 
Join Date: Aug 2003
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can also try and place an ADODC control (ADO Database Control) on your form and right click on that one to get the properties.

There you can create a connection using a wizard and you get the connection string.
After that you can compare the connectionstrings.

Hope it helps

Greetz

Tom.
 
Old June 8th, 2004, 04:32 AM
Authorized User
 
Join Date: Mar 2004
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

connection string it produces is the same - at least I know the string is correct.
still doesn't like the cnPubs.Open strConn
 
Old June 8th, 2004, 08:32 AM
Authorized User
 
Join Date: Aug 2003
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I may have another suggestion.

When I have to connect to an SQL Server using VB I do not use:
PROVIDER=SQLOLEDB

But i use
PROVIDER=SQLOLEDB.1

Although I use VB6 and to be honnest I do not know what the difference is between the two, it still may be worth a try.

Maybe this one helps.

Regards

Tom.
 
Old June 8th, 2004, 09:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there...
another idea..

do you know what is a .udl file??

try to make one and copy the connection string to your app...

HTH

Gonzalo





Similar Threads
Thread Thread Starter Forum Replies Last Post
VB4 Problem countrymusicman Beginning VB 6 3 September 21st, 2009 07:45 PM
Migrating from VB4 to .Net Kika VB How-To 1 November 8th, 2007 11:36 AM
SQL2000/MOM2005 Hugo22 SQL Server 2000 3 February 23rd, 2007 09:48 AM
Making DLL from VB4 Zooker Beginning VB 6 0 July 11th, 2004 02:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.