cancel
Showing results for 
Search instead for 
Did you mean: 

OleDb connection, how can I specify "Extended Properties"?

former_member560462
Participant
0 Kudos
466

I am porting an application that used CR XI, the COM interface, to CR Visual Studio 2010 using the CR .net api. The reports do SQL selects from tables accessed via an ole db provider. I need to be able to specify the "Extended Properties" component of the OLE DB connection string. In the CR XI version of this, I used get_ConnectBufferString on each table, appended my "Extended Properties" info, then used put_ConnectBufferString to update the now modified connection string. This worked like a champ.

WIth the .net SDK, I am struggling to see how to accomplish this. I have a ConnectionInfo class which I can set server, database, username, and password. That's nice, but I can't figure how to get my Extended Properties in there. Is it possible to do this in any way?

By extended properties, I mean something on the order of this:

Provider=myOleDbProv.myOldDbProv.1;Data Source=<server>; Extended Properties="myProp=myVal" etc. etc.

--

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hello,

See this kbase article to get an app that will get your connection info and then generates the code required to use it in your app:

1553921 - Is there a utility that would help in writing database logon code

You could also use a UDL file to make the connection info.

Don

former_member560462
Participant
0 Kudos

I had a look at the app. Before I have a go at that, though, a UDL file would be fine. However, this particular application wants to change the connection parameters at runtime. The local of the UDL file will change, and its contents will change. So, again at run time, I can whip up the appropriate UDL file on the fly. Given that I've done that, and it is, say, c:\foo1.udl, how can I tell my report to use that particular file at runtime to connect to my table?

0 Kudos

Same app. Use it to decompile your report based on a UDL.

Don

former_member560462
Participant
0 Kudos

What I have is Crystal Reports for Visual Studio 2010. What do I actually need to do app suggestion?

System.InvalidOperationException: The ReportClientDocument property can only be accessed when the report is opened using a Report Application Server.

at CrystalDecisions.CrystalReports.Engine.ReportDocument.get_ReportClientDocument()

0 Kudos

Hello,

RAS is the better engine. Open the report with the engine and then use RAS as much as possible. Lot's of sample in this forum. Then search here on ReplaceConnection_click and it has the code you need to use plus the extra properties once you run the other app.

Add all of these to your app:


using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ReportDefModel;
using CrystalDecisions.ReportAppServer.CommonControls;
using CrystalDecisions.ReportAppServer.CommLayer;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ObjectFactory;
using System.Data.OleDb;
using CrystalDecisions.ReportAppServer.DataSetConversion;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Windows.Forms;
using System.Data.SqlClient;
using System.Runtime.InteropServices;

And then add this:

	public class frmMain : System.Windows.Forms.Form
	{
        CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
.....

And on open use this:

private void btnOpenReport_Click(object sender, System.EventArgs e)
{
            rptClientDoc = new CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocument(); 

            openFileDialog.Filter = "Crystal Reports (*.rpt)|*.rpt|Crystal Reports Secure (*.rptr)|*.rptr";
            //openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex = 1;

     	    if (openFileDialog.ShowDialog() == DialogResult.OK) 
	    {
	     	btnOpenReport.Enabled = false;
		btnSaveRptAs.Enabled = false;
                btnCloserpt.Enabled = false;
		object rptName = openFileDialog.FileName;
                
                try
                {
                    // open with the engine always
                    rpt.Load(rptName.ToString(), OpenReportMethod.OpenReportByTempCopy);
                    // this sets the report to RAS and now you can use either.
                    rptClientDoc = rpt.ReportClientDocument;
                 }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR: " + ex.Message);
                    return;
                }
...

Don

former_member560462
Participant
0 Kudos

The OpenReportMethod::OpenReportByTempCopy was the key to the resolution to this (yes, I am attempting to do this in c++ although I may bail on that). I had this in my initial go, and couldn't even compile it. Some nonsense about needing assemblies that I couldn't even find with Add Reference. It turned out to be a conflict with previous installations of CR. I had Visual Studio Basic for VS2008 installed. That apparently had version 10.5.something of CR installed. I also had Visual Studio 2005 installed. That apparently had version 10.2.something of CR installed. After I removed both of them and rebuilt my my test app using the PropertyBag stuff referenced in your post a few back as well as the OpenReportByTempCopy, I was able to connect to my OleDbProvider with my Extended Properties set on the fly. Hopefully my Jet Database connection will be as successful. Thank you.

--

0 Kudos

Hi again,

Great... All you had to do was add an App.config file and tell it to use the 13.0.2.x files. Or I think Managed C++ app's use it, if not hen in typically in your Main.ch file you can add the references using the full path. It' been a while since I tired it. Mixing CR versions will definitely cause problems. Make sure the CR.Windows.Form is the correct version also.

You should move to C#, same as C++ but much easier once you get the hang of it... And there really is no advantage using C++ over C#, or at least when using CR runtime...

While you are at it you really should get off of the Jet DB also. PC databases are a pain when using in 64 bit mode, and most PC databases don't support them. ODBC may be easier but what ever works for you...

We do have one C++ sample that may help:

http://wiki.sdn.sap.com/wiki/display/BOBJ/CrystalReportsSDKSampleApplications

Thanks again

Don

Answers (0)