Peter
-
1/21/2011 3:13:17 PM
GeneralConnection, Named Queries and External Databases
Scenario:
I have need to pull data from an external database table to populate a UniGrid. I wrote a named query in a related Custom Table and instantiated a CMS.DataEngine.GeneralConnection object using a Connection string that pointed to the external database.
Issue:
The GeneralConnection.ExecuteQuery(string queryName, object[,] parameters, string where, string orderBy, int topN, string columns, int offset, int maxRecords, ref int totalRecords) method throws the error:
[DataConnection.ExecuteQuery]: Query: Proc_CMS_Class_GetQueryByName: caused exception: Could not find stored procedure 'Proc_CMS_Class_GetQueryByName'.
Thoughts:
I would assume the DataConnection object, now pointing at the external database, is trying to find the Proc_CMS_Class_GetQueryByName stored proc there instead of looking in the Kentico database like it should. However, interestingly enough, SOMETIMES it works?!?
There are work arounds to this for sure but I prefer to use Kentico's objects when I can. I'm not sure if ExecuteQuery method was ever meant to be used this way BUT Kentico does allow it to be instantiated with a different connection string so I would suggest that, at some point, the method NOT assume the database it is connected to is the Kentico database when attempting to access Kentico DB objects (perhaps it can grab the default Connection object and call whatever Kentico objects are needed from that?).
Can't say this is a bug I'd like to use this method b/c it handles the UniGrid's OnDataReload event parameters nearly one-to-one.
|