Connecting crystal reports to oracle database using vb.net code - vb.net

I'm using crystal reports 9, visual studio 2008, and oracle 9i in this project I'm doing. My crystal reports pull data from an oracle database, and are displayed on a CrystalReportViewer on a windows form. How would I make this connection using vb.net code?
Imagine this little scenario:
The host name for the oracle server is myHost.
The database name is myData
The username is myUser
The password is myPass.
Please assist me with the code to make this connection.
Your help will be highly appreciated.

Basically, you have a few options. If you've created a connection inside of the Crystal Report then you can hand off different login credentials to the report and crystal will handle it. You have to do it in a specific way through or it won't work (it's very picky on the order in which it's done). You will loop through the report and all the sub reports handing off new crendentials. The second route is to use a DataTable as your DataSource, populate it via VB.Net and hand it off (this doesn't sound like the route you're wanting to go).
Here are two blog entries where I describe how to pass new login credentials off to Crystal.
https://www.blakepell.com/2010-09-17-crystal-reports-changing-the-database-connection-from-net-subreport-links-and-the-case-of-the-missing-parameter-values
https://www.blakepell.com/2012-05-22-crystal-reports-extension-methods
In the first blog entry there is a "Private Sub ApplyNewServer(ByVal report As ReportDocument)" that will show you how to pass your new login and server information. It was extracted from another class so it might need slight modification to reference the login parameters you want to pass in.
Best of luck. ;)

Related

Running/Printing a report from VB6 application using ACCESS with data loaded from Sql

I have a simple VB6 application where I input information and store it on SQL SERVER. I went ahead and linked Access 2007 and SQL Server so that all my tables are in Access for report generating purposes. I created a mock report, and was able to generate a report for all users from the sql Table (from Visual basic) Now my question is this, on the report form in the VB application, I have a combobox that's being populated with Client Names from the sql server. What I need to do is allow the user to choose a name from the combobox and click PRINT and allow them to only generate the report for that one user. The names in the combobox have ID's assigned to them. I'm having a hard time coming up with a way to edit the query in access (where id=17) from VB to allow the report to be only generated for one user. Thanks for any and all help!
Dont you think that sending a query from VB6 to Access would be a better way instead of modifying the queries in Access.
Hope I understood your question correctly.

Does Crystal Reports store user / pwd in a report file?

We have one report that when run throws an error stating "Database login failed". I have 20+ reports configured the same way that execute without any problems. In the Crystal Reports Designer, I verified the database and everything is good. The sql queries used to generate the report look good.
The reports are run from an ASP.NET application. We're not using a report server. We're using the 13.x runtime on the server. Reports are defined in CR Designer and passed parameters from the ASP.NET application.
Can Crystal store a username and password in the report file? How do I clear any saved values? Any other ideas? I'm a bit lost here since everything else is working just fine.
Yes. Crystal can store authentication/connection info in the .rpt file. You can override this with your ReportSource definition by setting parameters.
It most definitely does NOT store account/password in the RPT file.
You will need to explicitly set the authentication credentials.
It does not store the password. It does store the ID most of the time. The reason some reports work sometimes has to do with if Windows authentication indicates you have access to the data.
The safest most consistent way to run reports is to use the ID/password evertime, although in some cases, if it's expecting Windows authentication only, putting the ID/password will cause it to fail.

Crystal Reports

I have installed Crystal Reports and am using it in Visual Studio 2005.
Can anyone help me as to how i can use SQL Server 2000 to generate reports using Stored Procedures.
Im not sure i have understood the question. if you want SPs to write the RPT file for you then I cant answer.
What i have done for years is use Stored Procedures to do the heavy-lifting for the report. Simply create an sp with parameters. When you create your crystal report and adding data definitions in make sure that stored procedures are included. Then add parameters to the report which are inserted into the SP paramaters at runtime.
Using Views is also a good way to put all the data massaging work back onto the db server instead of the client. Send parameters from crystal to return a filtered dataset back to your report for printing.
Crystal Reports: Tutorials and Sample Code
http://msdn.microsoft.com/en-us/library/ms227881%28VS.80%29.aspx
Google search of "Crystal Reports Visual Studio Tutorial" returned that as the top result.
Start by creating a data source type of OLE DB, and choose your SQL Server Native Client. This option will be there for a new report, or if you set the data source; note that if you set a different data source for an existing report, your existing data fields may disappear from the report. Using integrated security is nice because you can control access to the data in the report in SQL Server.
Then in your database expert, click "Add Command", where you can call the shared procedure, add SQL, select your fields, etc.

extract raw SQL query from a Crystal Report .rpt file

I've got an .rpt file that I did not write and can find no documentation about. I want to be able to review the SQL that is generated from this report so that I can figure out, well, what data it was pulling and what WHERE clause parameters were used.
I can open it up and see the report layout. But when I select Database|Show SQL Query... the report tries to connect to the data source. The problem is, the data source being used is unknown to me, probably an ODBC connection used by whoever wrote the query. All I can do at that stage is 'Cancel' and I'm back to looking at the report designer.
Am I missing something? Can I get to the SQL query without connecting to the datasource? It seems like viewing the selection criteria shouldn't be dependent on a data connection.
Thanks.
version: Crystal Reports 2008
I know that this is an old thread, but I encountered this same problem. Effectively we used to have a database/application that has since been aquired by an external agency.
Although they now have the database/application they don't have access to crystal reports, so we can't just send them the old report that we used to run. Likewise we can't run it as we don't even have the database set up anywhere.... So instead our plan was just to extract the SQL code generated by the report and forward that on.
We experienced the same problem, but the solution is actually pretty simple.
If you don't have access to the original data source, just create a new 'blank' datasource (such as an ODBC connection). As long as the connection to the datasource works (i.e. it is some kind of valid datasource this it works fine). When running the 'Show SQL' option point the report to this datasource. As long as you don't try to actually run the report (and only show the SQL) the operation wont fail. This worked for our situation anyway. (Crystal Reports 2008)
(I can give more details if it helps in any way.)
It should be possible to find out some details about the existing datasource, by selecting Database > Set Datasource Location... .
As well as enabling you to change the datasource location, this should show you some information about the current datasource, such as which type of datasource is being used, and possibly (dependant on the type of driver) the name of the database. It is likely to be less helpful if (as you surmise) the datasource is ODBC, but if it uses a native driver there may be something useful.
Without the password, I'm not sure how much you can do. It seems "Show SQL Query" requires to report to run first, then generate the SQL plan.
It's not ideal, but you could go to Database > Visual Linking Expert to at least see the tables and how they are joined, and the go to the Record Selection Formula Editor and see what the custom WHERE statements are.
Viewing the SQL of a Command in a Crystal Report File
There are times you have just the report file, but not the associated database structure that the report uses.
This is common when dealing with example reports of functionality you wish to mimic.
This is a workaround ONLY to allow you to see the SQL of a Command that a Crystal Report is based on, when you don't have the underlying database connection that the report is based on.
In essence, the dialog box has to be satisfied before it will show the SQL, so we fool it with a legitimate Data Source, just not one that would work with the SQL that is actually in the SQL Command.
Why does a report use a command? Doesn't Crystal Reports have the ability to link tables?
When a Crystal Report is based on a record set that is too complex for the table linking functionality within Crystal Reports, the report can instead be based on a SQL Query, usually developed/tested in another editor tool and pasted into the command. This allows advanced SQL functions to be utilized.
If you don't already have a Data Source on your computer set up that you can connect to, you will need to build one first.
A simple Microsoft Access .mdb file saved in a simple location will suffice.
I placed mine with the path C:\A_test\test.mdb to make it easy to find.
If you don't have one, google for a sample mdb file and download it, saving it with a name and location you can remember. (You won't ever actually open this file, but just connect to it.)
Once you have the file saved, open the ODBC Administrator and create a New Data Source.
(you can get to the ODBC Administrator quickly from Start > type ODBC in the Search)
On the User DSN tab, click the Add button.
Scroll down the driver list to Microsoft Access Driver (*.mdb), select it and click the Finish button.
In the Data Source Name box, type a name (I used MyTest).
Click the Select Button and select the mdb file you saved from a previous step, click OK.
Click OK again. You will see your new Data Source listed by the name you gave it. Click OK.
You now have the data source you will need for the next steps.
Open the Crystal Report you want to see the SQL command for, and click on Database Expert button or Database>Database Expert Menu.
Under Selected Tables, right click on the Command and choose View Command
The Data Source Selection Box appears. Select the Data Source you created (or one you already use) and click the Finish button. The View Command box should open with the SQL in the left pane. Copy the SQL into your favorite text editor.
Whats happening is that the crystal reports needs a database to connect to regardless if its the original source DB or not.
Create a local database or use a database stored on a server, added it to your ODBC Datasources and use it when connecting. After a successful connection you should be able to view the SQL query without an error.

Connecting to Crystal Reports 4.6 from VB

How can I connect to a Crystal Reports 4.6 report that connects to SQL Server 2005 as a data source, using Visual Basic?
I don't want to specify the connection string in the report. I want to pass the connection from VB. Is there any way to do this?
A long time ago I worked on Crystal 4.5 (I don't remember a 4.6). The way to change the connection details is still pretty much like it is today - Find the tables collection for each report and set the location & log on information for each one. Sub reports were a pain though. You had to go through each section of the report to find out if it contained a subreport, then get its table collection.