Skip to Content

Remove only 'Database' from DataSourceConnection Logon Properties

Background: winform app using Cr for VS (SP10), VS2013, ODBC connection to SQL Server.

Using Crystal Reports Designer, Set Data Source Location, one can manually blank out just the 'Database' property for an ODBC data source. This causes the Database property to be removed from the connection properties. I need to achieve the same effect in code (just at runtime, no need to permanently update the rpt).

Testing with a simple report with a DataSourceConnection(0) that has 3 Logon Properties (Database, DSN, and UseDSNProperties).

Dim MyReportLogonProperties As NameValuePairs2

MyReportLogonProperties = ReportN.DataSourceConnections(0).LogonProperties.Clone

MyReportLogonProperties.Remove(MyReportLogonProperties.LookupNameValuePair("Database"))'

' note: at this point the number of LogonPropeties in the clone is indeed down to 2.

ReportN.DataSourceConnections(0).SetLogonProperties(MyReportLogonProperties)

' at this point, there are 5 LogonProperties: DSN, PreQEDatabaseName, PreQEServerName, Trusted_Connection, UseDSNProperties

I believe the PreQEDatabaseName that is added for some reason by the runtime is blocking the attempt to remove the 'Database' property.

To recap: is there a way to remove just the 'Database' property from the LogonProperties of a DataSourceConnection?

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Jul 22, 2014 at 01:23 PM

    Hi Ido,

    Thank you for posting this to SCN....

    Pre-CR 9 days when you could remove the database name from the connection info CR would "pickup" the database from the connection you had open because you had to be connected to a DB before you could do anything in the Designer. When we completely re-wrote the database connectors and removed it from the crw32.exe they created a new QueryEngine and CRQE dll's thus we removed all "custom" DB driver "hacks" from the dll's which forced DB Clients to "follow the rules". ( too tough to maintain )

    Since then CR 9 and above fully qualifies all Database info in it's field references and anything related to a database name, table and field.

    If you run in debug mode you can see this, for MS SQL it's typically Database.dbo.table. If we don't fully qualify and someone else owns a table of the same name you were never sure which DB you actually got data from ( all depended on where the pointer was on the Server and if there were multiple DB connection in the Designer - Subreport to the same Server and different Schema with same table name but different Database as an example). CR only has one HDBC handle but spawns multiple Handles over the same connection.

    So now all of this info is saved in the RPT file and there is no way to not save it even at runtime, because all field references must have a fully qualified source so CR knows exactly where to get the data from.

    So even though you are blanking out the Database properties in UI, in the backend we still have it fully qualified and therefore will not allow you to blank it out in the SDK. And it actually makes no sense to set it blank because now CR has no idea how to build the SQL because MS doesn't allow dbo.table to be used.

    Bottom line is even setting it to nothing in CR Designer the rpt still has it referenced because you had to select it when you designed the report, it's just the UI allowing you to blank it out.

    And it's not clear why you want to do this? You still need to set it so why start from nothing, you are simply replacing it anyways in code. Security issue possibly???

    Hope that explains it?

    Thanks again

    Don

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.