Visual Studio Development Bookmark and Share   
 index > Crystal Reports for Visual Studio > Changing Datasource at runtime [UNRESOLVED]
 

Changing Datasource at runtime [UNRESOLVED]

THe following applies to Crystal Reports for Visual Studio 2005 v10.2.3600.0

When I change the datasource of a report at runtime to anything other than my development machine, I am getting the following errors...

"The field name is not known."
"Error in File..."
"Error in formula <Monday>"
'{?@StartDate}'
This field name is not known

Note: **This paramter is created from the stored procedure used to create the report

Failed to open a rowset, procedure expects parameter @LocationID which was not supplied.

Note: **the parameter is supplied during runtime

I have reproduced the following several times.

1. Created a report that gets data from a stored procedure having
parameters on sql server

2. create a vb.net project with a crystalreportviewer control

3. bind the report to the control at runtime

4. at runtime, the viewer control will ask the user to input values for
the params

5. report loads as expected

During step 3, if the database location is changed to a different
server than the one used when developing the Crystal Report, the
following will occur.

-->4. at runtime, the viewer control will ask the user to input values
for the params

-->5. report loading fails with an ADO error stating the stored
procedure expected parameters that were not supplied.

This works backwards as well, meaning I then create a report using the production server, then change the datasource at runtime to my dev machine which gets the same results as above.

sectorFive  Wednesday, November 22, 2006 10:28 PM

I added the following code after reading some posts...

Try

rpt.VerifyDatabase()

Catch ex As Exception

MessageBox.Show(ex.ToString)

End Try

This traps a logon error... I have tried the following code to set the datasource

rpt.DataSourceConnections.Item(0).SetConnection(conn.DataSource, conn.Database, False)

rpt.DataSourceConnections.Item(0).SetLogon(user, pass)

AND

Dim conns As DataSourceConnections = rpt.DataSourceConnections

Dim info As IConnectionInfo = conns(0)

info.SetConnection(conn.DataSource, conn.Database,user, pass)

AND

'Set the db logon info

With crConnectionInfo

.ServerName = conn.DataSource

.DatabaseName = conn.Database

.UserID = user

.Password = pass

End With

'Loop through each table in the report and apply the LogonInfo information

Dim CrTables As Tables = rpt.Database.Tables

For Each CrTable As Table In CrTables

crtableLogoninfo = CrTable.LogOnInfo

crtableLogoninfo.ConnectionInfo = crConnectionInfo

CrTable.ApplyLogOnInfo(crtableLogoninfo)

Next

sectorFive  Wednesday, November 22, 2006 10:37 PM
Anyone with any ideas?
sectorFive  Friday, November 24, 2006 5:13 PM
Is it possible that there is a slight difference in the stored procedures between the two servers. Different capitalization, data type, etc.
mewdied  Friday, November 24, 2006 7:45 PM
Unfortunatly not. I have several vs2003 projects that run fine, its only my vs2005 projects that i have a problem with.
sectorFive  Monday, November 27, 2006 2:19 PM

Hi,

Just had the same problem in VS2005. I managed to solve it with the following code:

                          Report.Database.Tables[1].ApplyLogonInfo(LogonInfo);
                          Report.Database.Tables[1].Location = "Name_SP;1";

So basically, after applying the new logoninfo, you have to set the table location again so it removes the old server name from it.

Cheers,

Simon.

Glantzie  Wednesday, December 20, 2006 10:37 AM
I solved this by installing the Crystal Reports hotfix for Crystal Reports.NET

technicalsupport.businessobjects.com
KBase Article ID=c2018840

Or, just download hotfix from
http://ftp1.businessobjects.com/outgoing/CHF/crnet20win32x86_en_chf.zip
OLD PROFILE  Tuesday, January 09, 2007 5:23 PM

Dim crReportDocument As New ReportDocument

Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table

Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

For Each tbCurrent In crReportDocument.Database.Tables

tliCurrent = tbCurrent.LogOnInfo

With tliCurrent.ConnectionInfo

.ServerName = gServer

.DatabaseName = gDataBaseShr

.UserID = gUsername

.Password = gPassword

End With

tbCurrent.ApplyLogOnInfo(tliCurrent)

'

'Conectar a la base de datos correcta

'

tbCurrent.ApplyLogOnInfo(tliCurrent)

Dim sLocation As String = tbCurrent.Location.ToString()

Dim iposPunto As Integer = sLocation.IndexOf(".")

sLocation = Convert.ToString(gDataBaseShr & ".dbo." & sLocation.Substring(iposPunto + 1))

tbCurrent.Location = sLocation

Next tbCurrent

Ing. Miriam Escuadra  Thursday, February 01, 2007 9:01 PM

Thank you Glantzie! I'll have to put you on my Heroes list.

Andno thanks to anyone involved in the development of Crystal Reports. There is no good excuse for the dozens of problems thatCrystal Reportshas and continues to have, version after version after version. Only a poorly-run company would allow such a marketable product to continue with such poor quality. Fortunately, Microsoft's reporting product is currently a close second as far as competitive features go, so it won't be long before the Crystal company (currently Business Objects?) is sueing Microsoft for putting them out of business by creating a superior product.

TLunsf  Monday, March 19, 2007 11:13 PM
I was download hotfix from
http://ftp1.businessobjects.com/outgoing/CHF/crnet20win32x86_en_chf.zip

I try to run again, the error not fine again in my PC ( Source Program )..

I Has build,publish dan install setup in client PC
But in computer client still error...

keyung  Wednesday, March 21, 2007 7:48 AM
I too owe Glantzie big time on this one. I did a ton of searching on this issue, but this was the first suggestion that worked!!

Thanks
Evets17  Wednesday, June 13, 2007 2:25 AM
The hotfix fixed this issue for me. Thanks a lot "OLD PROFILE" :-)

Sagar Agrawal  Wednesday, June 24, 2009 9:13 PM

To all,

Here are the stupid codes to change the datasource at runtime,

foreach ( CrystalDecisions.Shared.IConnectionInfo conInfo in report.DataSourceConnections)
conInfo.SetConnection("servername", "database", "username" , "password");

// this is the wierd code I've ever seen but it work. you need to re-assign the value to itself. Amazing hehehe
foreach(Table tb in report.Database.Tables)
{
string tLoc = tb.Location;
tb.Location = tLoc;
}

apdoniariel  Monday, October 12, 2009 5:04 PM

You can use google to search for other answers

Custom Search

More Threads

• ClickOnce Deployment when not administrator
• Print Document Portions to Different Trays
• Binding data to an IFieldObject
• Report Design capability at Runtime in VS C# 2005 WinForm Application
• Loadsaveexception
• Crystal Reports Date Parameter Problem
• Crystal Reports Suppression Logic in Code
• Crystal Reports and LINQ
• Passing value from ADO.NET to fieldobject
• Setting Datasource a runtime for Crystal XI