Invalid Argument Exception


Author
Message
PeterA
PeterA
StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)
Group: Forum Members
Posts: 72, Visits: 235
I'm getting a strange error when I attempt to fill a business object from a DB2 database. I know I must be missing something simple (having just now figured out what I was doing wrong with not being able to even try filling a business object), but I'm just not seeing what the problem is.



First, here's the stack trace:





IBM.Data.DB2.DB2ConnPool.a(String A_0, a& A_1, c& A_2) +11132

IBM.Data.DB2.DB2Connection.set_ConnectionString(String value) +353

MicroFour.StrataFrame.Data.Db2.Db2DataSourceItem.CreateBlankDbConnection() +62

MicroFour.StrataFrame.Data.DbDataSourceItem.GetDataTable(DbCommand Command, OnChangeEventHandler CallBack) +73

MicroFour.StrataFrame.Data.DbDataSourceItem.GetDataTable(QueryInformation QueryInfo, OnChangeEventHandler CallBack) +56

MicroFour.StrataFrame.Data.DataLayer.GetDataTable(QueryInformation QueryInfo, Boolean RegisterNotification) +154

MicroFour.StrataFrame.Business.BusinessLayer.FillDataTable(QueryInformation QueryInfo) +54

Payless.Sourcing.MaterialsManagement.SuppliersListing.Page_Load(Object sender, EventArgs e) in I:\PSS Design\Visual Studio\Materials Management\MM_UI\Suppliers\listing.aspx.cs:54

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +47

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061





What I'm doing is creating a connection which is added to the DataLayer (i.e. mySqlh). I then build a QueryInformation object to get that would fill the business object (i.e. qBizQuery), set the business object's DataSourceKey to the same as the DataSourceKey I just created (from a Web.Config file) and then attempt to fill the business object.





DataLayer.DataSources.Add(new Db2DataSourceItem(Global.Config['DataSourceKey"], connectionString, IBM.Data.DB2.DB2Factory.Instance);



mySqlh = DataLayer.DataSources[Global.Config['DataSourceKey']];



qBizQuery = new QueryInformation();



BizObject.DataSourceKey = Global.Config["DataSourceKey"];

BizObject.FillDataTable(qBizQuery);





The mySqlh object is actually used further down in my code to build a dataset for a gridview control.



So, finally to my question: am I attempting to implement the business objects correctly? Am I missing something else that is causing this invalid argument?



Thanks!
StrataFrame Team
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Sorry, but I don't see anywhere where the exception message is listed... just the stack trace.

As for your code, yeah it looks good.  The only thing being that the default BusinessObject.DataSourceKey is "" (string.Empty), so if you only have one database connection, you can just supply string.Empty as the DataSourceKey when you create the Db2DataSourceItem and not worry about retrieving it from the config anywhere.  If you have more than one connection string, then you'll certainly need to come up with some unique DataSourceKeys.  And the DataSourceKey is ususally something that the developer specifies; it's independent of the connection string and only used as a dictionary key so that objects know which DbDataSourceItem to use to talk to the database, so you certainly don't have to keep it in a config file anywhere.

As for the QueryInformation object, you only have to use one of those if you need to a provider independent operation.  In fact, you will soon reach the limits of it because it's designed to be a simple tool to allow the business objects to perform simple operations without needing to know their underlying database type (i.e. fill by primary key, insert, update, delete, etc.).  The QueryInformation doesn't support much more than single table retrieval (no joins or tests on other table keys or anything).  So, in the cases when you are trying to run an advanced query (most of the time), you'll want to manually create a DB2Command object and use the business object's FillDataTable(DbCommand) method (don't worry about setting the connection on the command, just create it blank, because it will be set before the command is executed).

Using the DbDataSourceItem directly is perfectly fine, we show a few things that you can use it for during the training courses, so creating that mySqlh object is good.

So, strictly speaking, there's nothing you're doing wrong.  I'm not sure what might be causing the exception because I can't find the message anywhere.

PeterA
PeterA
StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)
Group: Forum Members
Posts: 72, Visits: 235
Sorry. I didn't include the exception piece. Smile Here's the whole exception and the stack trace:





[ArgumentException: Invalid argument]

IBM.Data.DB2.DB2ConnPool.a(String A_0, a& A_1, c& A_2) +11132

IBM.Data.DB2.DB2Connection.set_ConnectionString(String value) +353

MicroFour.StrataFrame.Data.Db2.Db2DataSourceItem.CreateBlankDbConnection() +62

MicroFour.StrataFrame.Data.DbDataSourceItem.GetDataTable(DbCommand Command, OnChangeEventHandler CallBack) +73

MicroFour.StrataFrame.Data.DbDataSourceItem.GetDataTable(QueryInformation QueryInfo, OnChangeEventHandler CallBack) +56

MicroFour.StrataFrame.Data.DataLayer.GetDataTable(QueryInformation QueryInfo, Boolean RegisterNotification) +154

MicroFour.StrataFrame.Business.BusinessLayer.FillDataTable(QueryInformation QueryInfo) +54

Payless.Sourcing.MaterialsManagement.SuppliersListing.Page_Load(Object sender, EventArgs e) in I:\PSS Design\Visual Studio\Materials Management\MM_UI\Suppliers\listing.aspx.cs:53

System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15

System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34

System.Web.UI.Control.OnLoad(EventArgs e) +99

System.Web.UI.Control.LoadRecursive() +47

System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061

StrataFrame Team
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
That's very strange that the ConnectionPool would be throwing an exception when you set the connection string.  I wonder if it could be something in the connection string that it's not expecting.  Have you tried hard-coding the connection string to make sure it's working?  Also, you might try the DbConnectionStringBuilder from the DB2 ADO.NET provider and see if it works any better.  Once you build it, you just have to .ToString() it to create the connection string.  I don't think the error is coming from StrataFrame because it is just passing along the connection string that you provided and the exception is being thrown by one of IBM's DLLs, so...
PeterA
PeterA
StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)
Group: Forum Members
Posts: 72, Visits: 235
I know the connection string works because I'd previously been retrieving data from the same database using the query object and datasources on the page. It's when I try to make use of the business object that it starts throwing the error. I'll try hard-coding it to double-check, but is there anything else that could be going on?

StrataFrame Team
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
I'm not sure.  This is the code from the Db2DataSourceItem for CreateBlankDbCommand():

Public Overrides Function CreateBlankDbConnection() As System.Data.Common.DbConnection
    Dim conn As DbConnection = Me._Factory.CreateConnection()
    conn.ConnectionString = Me.ConnectionString
    Return conn
End Function

All it does is create the connection and set the connection string.  The exception is being thrown by the middle line that is attempting to set the connection string.  So, the only thing I can think of that might throw an argument exception would be the connection string itself.  But, as you said, you're using it to retrieve data elsewhere.  So...

What you might try is replicating this code right here.  Use the same factory that you passed when you created the Db2DataSourceItem and create a connection and then try to set the connection string to the DataLayer.DataSources[""].ConnectionString and see if it throws an error.

PeterA
PeterA
StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)StrataFrame Novice (74 reputation)
Group: Forum Members
Posts: 72, Visits: 235
I did manage to track this down on Friday, but didn't get a chance to post what fixed it. What was happening was it picked up the new line character in the file it was reading for a password. Once I made sure it stripped that out, it worked fine.



Thanks!

StrataFrame Team
S
StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)StrataFrame Developer (4.4K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Excellent.  I'm glad you got it working because I was stumped Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search