Crystal Reports RDC making ADO connection in VB

I have a VB application that I have installed the Report design control into to allow users to create reports at run time. I want to place a pre connected report in the designer with the database connections already created as a template. Here is the code I am trying to use to make a database connection via ODBC to a SQL database with an odbc connection called "Leas" Can anybody see what I am doing wrong. This is example code that that I am trying to tweak to work for me. When I try to run it is stops at the first "Set ADOConnection" and states that I am "trying to use an invalid outside procedure"



Dim ADOConnection As ADODB.Connection
Dim ADOCommand As ADODB.Command

''Beginning of Database connections
    ' Open the data connection
    Set ADOConnection = New ADODB.Connection
    ADOConnection.Open "Provider=MSDASQL;Persist Security Info=False;Data Source=Leas Database;Mode=Read"

    ' Create a new instance of an ADO command object
    Set ADOCommand = New ADODB.Command
    Set ADOCommand.ActiveConnection = ADOConnection
    ADOCommand.CommandText = "Orders"
    ADOCommand.CommandType = adCmdTable

    ' Add the datasource to the report
    Report.Database.AddADOCommand ADOConnection, ADOCommand
DavidNPDAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DRRYAN3Commented:
You've added the appropriate version of ADO to your project references?

This is happening on your development machine, or on end user machine?

The error message you've provided in quotes does not exist on the MS MSDN or KB sites.  Is there a different message being returned?


DRRYAN3
0
DavidNPDAuthor Commented:
I believe I have the correct references installed, I am making other ado connections to this database in othere areas of the app. WOuld you know what reference I need for this type of connections?

This is my development machine.

Could this be a error generated directly from Crystal and that is why it is not on MSDN? the wording "trying to use an invalid outside procedure" is a exact.
0
DRRYAN3Commented:
The code above has nothing to do with Crystal until the last line.  The rest is all ADO stuff.  

Did you setup security on the SQL server?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

mlmccCommented:
it appears you have used parts of two different connection methods.

ADOConnection.Open "Provider=MSDASQL;Persist Security Info=False;Data Source=Leas Database;Mode=Read"


The standard ODBC connection looks like
ADOConnection.Open "Provider=MSDASQL;DSN=Northwind;UID=sa;PWD=;"

The OLE DB connectiion looks like
ADOConnection.Open "Provider=SQLOLEDB;Persist Security Info=False;Data Source=Leas Database;Mode=Read"

You may also be having trouble because of the blank in the Data source.

mlmcc
0
DavidNPDAuthor Commented:
DDRYAN3, I do have security on the server as I get in to the database with this "Leas" odbc connection in other software.

mlmmcc, You are right that was a type in my string with the space. I corrected that and still have the same issue. I copied this connection code directly from an example app so I am entirely unfamilier with it. Can you tell what lines should be removed or modified?

Here is the modified one:

Dim ADOConnection As ADODB.Connection
Dim ADOCommand As ADODB.Command

    ' Open the data connection
    Set ADOConnection = New ADODB.Connection
    ADOConnection.Open "Provider=MSDASQL;Persist Security Info=False;Data Source=Leas;Mode=Read"

    ' Create a new instance of an ADO command object
    Set ADOCommand = New ADODB.Command
    Set ADOCommand.ActiveConnection = ADOConnection
    ADOCommand.CommandText = "Orders"
    ADOCommand.CommandType = adCmdTable

    ' Add the datasource to the report
    Report.Database.AddADOCommand ADOConnection, ADOCommand
0
DavidNPDAuthor Commented:
DDRYAN3, I do have security on the server as I get in to the database with this "Leas" odbc connection in other software.

mlmmcc, You are right that was a type in my string with the space. I corrected that and still have the same issue. I copied this connection code directly from an example app so I am entirely unfamilier with it. Can you tell what lines should be removed or modified?

Here is the modified one:

Dim ADOConnection As ADODB.Connection
Dim ADOCommand As ADODB.Command

    ' Open the data connection
    Set ADOConnection = New ADODB.Connection
    ADOConnection.Open "Provider=MSDASQL;Persist Security Info=False;Data Source=Leas;Mode=Read"

    ' Create a new instance of an ADO command object
    Set ADOCommand = New ADODB.Command
    Set ADOCommand.ActiveConnection = ADOConnection
    ADOCommand.CommandText = "Orders"
    ADOCommand.CommandType = adCmdTable

    ' Add the datasource to the report
    Report.Database.AddADOCommand ADOConnection, ADOCommand
0
DavidNPDAuthor Commented:
I just realized the text of the error is not Exactly what I said, here is the correct one, When I attempt to run the code I get a dialog with this:

"Compile Error"

"invalid outside procedure"
0
mlmccCommented:
What version of ADO do you have or is ADO even installed on your machine?

mlmcc
0
DavidNPDAuthor Commented:
Sorry to sound stupid but How would I check that version #?
0
mlmccCommented:
I think there is program you can runto check.  I'm not at work but when I get back on Monday I'll run it down for you.

mlmcc
0
DRRYAN3Commented:
Re: version check program - go to http://www.microsoft.com/data and you can download and install both ADO (MDAC v2.5 or v2.6) and the MDAC version checker.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavidNPDAuthor Commented:
DDryan, I ended up solving this by an entirely different route,  but thanks for the assistance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.