on 03-30-2012 3:53 PM
Hi,
we have an issue with one of our reports (CR 2008, .NET 2.0, C#). The report references a table called "Events", which is present in dbo.Events and sys.events on the SQL server. The report works fine in the designer, but when showing it in our own application (and changing the database connection infos to a different SQL server) the following error occurs (translated):
---------------------------
Crystal Report Windows Forms Viewer
---------------------------
This field name is unknown.
Details: errorKind
Error in file ""Events-Tabelle {1CAFDF4D-625B-4B1B-AFEB-CFF0450DD78E}.rpt"":
Error in record selection formula:
'{Events.cID} = {?Pm-Tasks.lEventID}'
This field name is unknown
Details: errorKind.
---------------------------
OK
---------------------------
Apparently, it accesses the name in the wrong schema. How can we prevent that?
I use the following code to change the database connection to a new SQL server name (which works fine except in this case):
DbConnectionAttributes dbAttributes = new DbConnectionAttributes();
dbAttributes.Collection.Set("Auto Translate", "-1");
dbAttributes.Collection.Set("Connect Timeout", "15");
dbAttributes.Collection.Set("General Timeout", "0");
dbAttributes.Collection.Set("Integrated Security", false);
dbAttributes.Collection.Set("Locale Identifier", "5129");
dbAttributes.Collection.Set("OLE DB Services", "-5");
dbAttributes.Collection.Set("Provider", "SQLOLEDB");
dbAttributes.Collection.Set("Tag with column collation when possible", "0");
dbAttributes.Collection.Set("Use DSN Default Properties", false);
dbAttributes.Collection.Set("Use Encryption for Data", "0");
dbAttributes.Collection.Set("Data Source", serverName);
dbAttributes.Collection.Set("Initial Catalog", dbName);
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.DatabaseName = dbName;
connectionInfo.ServerName = serverName;
connectionInfo.UserID = "...";
connectionInfo.Password = "...";
connectionInfo.Attributes.Collection.Set("Database DLL", "crdb_ado.dll");
connectionInfo.Attributes.Collection.Set("QE_DatabaseName", dbName);
connectionInfo.Attributes.Collection.Set("QE_DatabaseType", "OLE DB (ADO)");
connectionInfo.Attributes.Collection.Set("QE_LogonProperties", dbAttributes);
connectionInfo.Attributes.Collection.Set("QE_ServerDescription", serverName);
connectionInfo.Attributes.Collection.Set("SSO Enabled", false);
connectionInfo.LogonProperties = dbAttributes.Collection;
table.LogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(table.LogOnInfo);
Use a multi part name
a table/view is
Database.Schema.table
if you are jsut using events each login could use a different schema
so use dbo.Events ( or sys.events) or even
database.dbo.events
BTW it's bad practice to use table name like "events" on for this reason.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
thanks to both of you for your comments.
> Use a multi part name a table/view is Database.Schema.table
I know that "dbo" needs to be prefixed. The problem is just that it doesn't work. I'd need to use "table.Location = dbName + ".dbo." + table.Location" to adjust the table location, unfortunately, it throws an error "cannot open connection" in this case. And that is after I called ApplyLogOnInfo() and table.TestConnectivity() returns true.
> BTW it's bad practice to use table name like "events" on for this reason.
There are quite a lot of tables in "sys.*", I don't think it's reasonable not to use any of these names. In particular since you should always have the possibility to use "dbo" only (except CR so far).
> If you are not trying to alter that parameter
I'm not doing that in code. This fragment is part of the report I process only to change the database connection.
> indicates you did not set the log on info in code for your subreports also.
Unfortunately, I'm setting the connection infos for both for the main and subreport.
Hi Florian,
Moved to .NET SDK forums.
'{Events.cID} = {?Pm-Tasks.lEventID}' indicates you have a subreport. Do not ever try to use the subreport parameter link directly. The one you can and should use will be in the Parameter collection, CR will handle and parameters that begin with "?PM-"
If you are not trying to alter that parameter then the error indicates you did not set the log on info in code for your subreports also.
Something like this, there are other ways to log, use your same method as you do in the main report object for each subreport:
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
table.Location = dbName + ".dbo." + table.Location
come up with error "cannot open connection"
I would look to see what table.location is after this update and try to connect using the multipart name
with regards to not using sys.table names, you could prefix all table names UT_weroifwoeji
I assume you are already doing this for Stored procs and views.
> I would look to see what table.location is after this update and try to connect using the multipart name
After this line of code table.Location remains the same.
> with regards to not using sys.table names, you could prefix all table names UT_weroifwoeji
Renaming files is out of the question currently.
Using a different new SQL user causes the same issue.
I also used the SQL profiler to check the statements being used. The only statement the profiler logs that happens in the affected DB, is the following statement:
SELECT | Events.sCalcLabel, DefTaskTypes.sName, Tasks.dzCompleteUntil, Tasks.lPriority, Tasks.lTaskFor, Tasks.dzRemindAt, Tasks.lSendUndoneNotificationTo, ... |
FROM | Tasks AS Tasks INNER JOIN |
Events AS Events ON Tasks.lEventID = Events.cID INNER JOIN | |
DefTaskTypes AS DefTaskTypes ON Tasks.eTaskType = DefTaskTypes.eTaskType | |
WHERE | (Tasks.cID = 10) |
It works fine when executed manually. Most likely, this statement is not actually the cause of the error, but a later statement (in a subreport I suppose). The SQL profiler doesn't generate any information on that though.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.