Changing a reports datasource at runtime

I thought I'd post this after wasting many hours of time with Crystal .NET v10. I

found a number of samples on CR's website that showed how to change datasource/user/pwd at runtime but none worked. The reports would always open the datasource they were originally designed against.
Call CrLogon() , the line of code that fixed everything and that was left out in all samples is
tbl.Location = tbl.Location in the AppllyLogon procedure. This line makes no sense and shows poor programming practices. Obviousily the set property does some work that should be done elswhere.
This is based on a KB from CR's site but their search engine will not find it but Google's did.
.....thank you Google. I now understand why CR is a freebie.

public shared function CrLogon(cr as ReportDocument, server as string, db as string, id as string, pass as string) as Boolean
'Use this to change the database logon info for a crystal report
dim ci as ConnectionInfo = new ConnectionInfo()
dim subObj as SubreportObject
ci.ServerName = server
ci.DatabaseName = db
ci.UserID = id
ci.Password = pass
if ApplyLogon(cr, ci) then
for each obj as ReportObject in cr.ReportDefinition.ReportObjects
if typeof obj.Kind.GetType() is CrystalDecisions.Shared.ReportObjectKind then
subObj = ctype(obj, SubreportObject)
if not ApplyLogon(cr.OpenSubreport(subObj.SubreportName), ci) then
end if
end if
CrLogon = True
end if
end function
private shared function ApplyLogon(cr as ReportDocument, ci as ConnectionInfo ) as Boolean

dim li as TableLogOnInfo
dim success as Boolean

for each tbl as Table in cr.Database.Tables
li = tbl.LogOnInfo
li.ConnectionInfo = ci
'check if logon was successful
'if TestConnectivity returns false, check logon credentials
if tbl.TestConnectivity() then
'drop fully qualified table location
if tbl.Location.IndexOf(".") > 0 then
tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1)
tbl.Location = tbl.Location 'THIS IS LINE LEFT OUT IN ALL SAMPLES I SAW
end if
success = false
exit for
end if
success = True
end function

Mike Schellenberger - MCAD
5/18/2004 12:09:18 PM 7043 articles. 0 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 51

Thanks for the code!

Were you using CR 10, or CR.NET? They are two separate products. There is no CR.NET v10. CR.NET could be described as CR 9 "lite", and has limitations. When you purchase CR 9 or CR 10, you're purchasing a more robust and powerful document object.
If my post is your answer, please mark it as the answer. It will bring good karma.

Crystal Alliance
My Blog
Florist Blogs
5/18/2004 5:02:22 PM
V10 is crap to.
Mike Schellenberger - MCAD
5/18/2004 6:04:41 PM
Let me clarify the previous. 

We bought V10 Developer which works with .NET, a support tech told me V10 is is basically the same as what came with VS.NET.
The V10 product installed the V9 help as a seperate install but did not update help in Visual Studio. CR support says use V9 documentation as little has changed for 10 (WRONG). I'm not sure what the .NET version is 9 or 10 or both or what.
I've never ever seen such a confusing mess of stuff, avoid Crystal Reports if you value your time and sanity.

Mike Schellenberger - MCAD
5/18/2004 6:17:19 PM
>I'm not sure what the .NET version is 9 or 10 or both or what

Neither, and you got some lousy advice if they said V10 is "basically the same as what comes with .NET". No wonder you're mad!
If my post is your answer, please mark it as the answer. It will bring good karma.

Crystal Alliance
My Blog
Florist Blogs
5/18/2004 8:24:59 PM

Similar Artilces:

Converting Crystal Reports 9 report to Crystal Reports .NET report
I have a web page that is supposed to display a crystal report.  The report is fully written and functional in crystal 9 (non-.Net)  .  Is there a way to convert my .rpt so that I can just include it in the new web site? why you don't try to compile project with .net and include your report. then if crystal report is power tool will suggests you with conversation tool    My blog is here.Please remember to 'Mark as Answer' if this post answered your question! Wow it really was that easy!  I just added the old crystal report into my .NET proj...

crystal reports .net -> crystal reports .net 2003
recently converted a project from .net to .net 2003. The 2 crystal reports I had in the project do not load when executing the application. The project itself within 2003 will allow me to multiplat the crystal reports, however when it comes to execution time I get the error: Invalid Data Source. If this isn't the right forum please point me to the right one as this is really the only website I know of with a large reader base. >to multiplat the crystal reports To what the crystal reports? Do you have the same database connections established and verified in your 2003 s...

RunTime Report With Crystal Report
hi dears. I'm a new user and work with C#. i want create RunTime Reports with Crystal Report. but i can't. I can't send parameters in C# programs to Crystal Report File. i want list fileld's in my program. and select Choice Field's. and send to crystal report file. then report that field and values. for example : i select in program name and family and phone number and home address. and click to report. and send that parameters to report file. name family phone address ---------------------------------- xxxxx xxxx1 4341254 ...

integration of Crystal Report with .NET ; crystal report viewer not displaying in Toolbox
Hi I m new to Visual Web Developer 2005 Express Edition. I want to integrate Crystal Report with .NET. In my Toolbox , Crystal Report Viewer is not displaying. How to make it possible? + How to call my report from 2.0. Need source code plz.*Share Knowledge Every TIME Crystal Reports for .NET does not come with VWD Express.  It only comes with VS 2005 Professional (I'm not sure about the Standard edition).If you have Crystal Reports 10 or XI, you can installed the .NET libraries for Crystal and then use them within VWD Express, noting that you have to build your reports ...

Is it possible to assign datasource dynamically at runtime to crystal report(.rpt) with VB.NET 2.0??
Hi experts, Can any one suggest me Is it possible to assign datasource dynamically at runtime to crystal report(.rpt) with VB.NET 2.0??I can only use Datasets in my case!! Typed-datasets are column-fixed right!!! But my data I assign is dynamic???? I actually gave a typed dataset having datatable with 4 fixed column  as datasource to crystal report .rpt at design timeBelow is my piece of code    Dim mydt As DataTable = New DataTable            schemadt = DummyTable() 'Function to retrieve Data TableDim r...

Cassini, VS.Net and Crystal Reports
Hi,I am working with Win XP home, Cassini and VS.Net.I would like to play with some Crystal Reports.I create the report in VS as CrystalReport1.I put a CrystalReportViewer on my web form. It does not get recognized as a defined object type but there are no build errors.When I run the app I get an error: Type 'CrystalReport1' is not defined.I have googled on this and see several things people have suggested/tried to correct this. Most I have already tried or the suggestions are not very clear to me. Then I came across a msg that instructed me to set up virtual directories for IIS for CrystalR...

VS .net 2005 Crystal reports ok to run on Crystal Reports XI?
I am getting mixed messages from the website hosting providers - some say they do not support Crystal Reports due to a $25,000 per cpu licensing fee, others say all I need to do is install Crystal Reports XI (about $500) on a dedicated server and it will run fine. Will Reports developed with the embeded Crystal Reports in VS 2005 run in a Crystal Reports XI environment? Thanks....

Are there other reporting tools other than reporting services and crystal reports
Has anyone had any experience with any reporting tools other than Reporting services and Crystal reports? If so, is there one that you would strongly recommend? Or, are these two the top choice on the market for report generation from .NET? I have heard some moaning and groaning about reporting services. Specifically in regards to the amount of time needed to design a report. Crystal reports seems kind of difficult to me, as I don't have any training with it. Basically I am looking for a reporting tool that is easy to use, and can be used from .NET....

Crystal Report.NET and nested sub reports
I have a report where i need to have several nested subreports... A parent may have childs and childs may have other childs and so on... CrystalReport.NET and VS2005 seems to support one level of subreport (a report could have a nested subreport but this nested subreport can't have another nested subreport). I really need to handle multiple levels of nested subreports in order to complete my report. What is the solution ???   Thanks   Eviral     I'm not positive if this works but its worth a shot.  Create the subreports as se...

Reporting (Crystal Reports vs. Custom .NET)
Ok, so I have to confess, I have never tried Crystal Reports. I just recently started working for a marketing company now and reporting is VERY important to them.  I am currently migrating a lot of the applications they use from VB5 and VB6 to web based .NET 3.5 apps.   The whole company is running off ACCESS databases if you can believe that.  They sometimes have up to a few hundred agents taking sales on incoming calls and chat sessions and they are all getting streamed to FLAT file records (completely un-normalized database).  I am in the process of developing a c...

Either the Crystal Reports registry key permissions are insufficient or the Crystal Reports runtime is not installed correctly.
hello Friends,I developing web site in 2005. Using inbuilt  crystal report for reporting.Development time its working fine but problem arise when i published site and upload in a web server.first some reference dll were missing so i copy them from gac and paste then in the bin folder for local reference.It works, but not i received the following error message:An error has occurred while attempting to load the Crystal Reports runtime.Either the Crystal Reports registry key permissions are insufficient or the Crystal Reports runtime is not installed correctly.Please install the ...

Runtime creation of crystal reports and fields, with all report sections
Hi! I'm a novice when it comes to crystal reports. I want to pass a customised query from a windows form (which might contain a statement like "SELECT * FROM " & tablecombo.text & " where (name = ' " & txtName.text & " ')" which could result in the following: SELECT * FROM Day1 WHERE (name = John) I want the report to be generated at runtime. Is that possible? If so, please show me how. If you mean to actually create a report dynamically at runtime, it may be possible in Crystal 9 and up, but not in Crystal .net. If you mean to dy...

View report from the crystal report server using .NET
Hi,I am first time dealing with crystal report and I having problem with it. I need to use to link to the crystal report server and view the report, but don't know how? Is there a way to do that? or is there any better way to using .net and view report from the crystal report server?Thanks....

Bind crystal reports / sql reports to ADO.NET
Hi,  I'm a beginner trying to find out if it's possible to directly connect an sql report/crystal report to an ADO.NET data set?   It all depends on what version of Visual studio you are using. Here are the steps for VS2005 In VS2005 you need to do the following: 1) Right click on your solution and select add, New Item. 2) Add a dataset and create your queries in the dataset. Make sure you save this dataset or it will not show up later. 3) Add your reportviewer 4) Right click on your solution and select add new Item Again and then add a crystal report 5) In the cr...

Web resources about - Changing a reports datasource at runtime -

Datasource - Wikipedia, the free encyclopedia
A DataSource object has properties that can be modified when necessary. For example, if the data source is moved to a different server, the property ...

Inverness Graham Acquires DataSource
Inverness Graham , a lower middle market private equity firm headquartered in suburban Philadelphia, has acquired DataSource , a print supply ...

SmartGlance for iPad for iPad on the iTunes App Store
Read reviews, get customer ratings, see screenshots, and learn more about SmartGlance for iPad on the App Store. Download SmartGlance for iPad ...

Chaitanya Pandit (@chaitanyapandit) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Data source - Wikipedia, the free encyclopedia
... Data source A data source is any of the following types of sources for (mostly) digitized data: a database in the Java software platform, datasource ...

2ndQuadrant - PostgreSQL expertise from specialists with a source code level understanding of RDBMS ...
PostgreSQL expertise from specialists with a source code level understanding of RDBMS PostgreSQL Planets Gabriele’s PlanetPostgreSQL Gianni’s ...

Tagged entries for CLOUD COMPUTING
Alan Williamson's output as a Java Champion, Blog-City Architect, BlueDragon Creator, Author, Speaker and Internet Guru

Private equity deals
... of biometric identity management systems, applications and services. Inverness Graham Investment has acquired DataSource ...

C# C Sharp and Tutorials on C#
Learn the c# langauge to build web applications using our online tutorials with live demos. Participate in our forums and learn from others. ...

JavaScript UI Library, Ajax Components & HTML5 Framework - DHTMLX
DHTMLX offers a rich JavaScript library, UI components & HTML5 mobile framework. Build impressive web apps for both desktop and mobile devices. ...

Resources last updated: 1/19/2016 7:33:42 AM