GenericDatabase not passing parameter to stored proc

Topics: Data Access Application Block
Jan 16, 2007 at 3:28 PM
I'm using the ODBC class to connect to a SQL Server db with the DAAB. I have a stored proc that takes one int parameter. I'm adding an "in" parameter and calling ExecuteReader. The command object shows the parameter in the debugger, but an exception is raised ("Procedure x expects parameter x, which was not supplied.") and the SQL Profiler shows that the parameter isn't being passed. Here's the code (I've genericized some names):

<WebMethod()> _
Public Function TransferFile(ByVal myParam As Long) As Integer
Dim db As Database = DatabaseFactory.CreateDatabase("myDB")
Dim cmd As DbCommand = db.GetStoredProcCommand("mySP")
db.AddInParameter(cmd, "@myParam", DbType.Int32, myParam)
Dim rdr As OdbcDataReader = db.ExecuteReader(cmd)
End Function

My connection strings are in web.config, and they seem to be working fine, but I'll include them here.
<ProviderName> System.Data.Odbc
<DSN> ActualDBName
<UID> UserID
<PWD> Password

On a side note, all it seems I need, as far as config files go, is web.config. I'm a bit confused about what I'd need ConnectionSettings.config or dataConfiguration.config for.
Jan 17, 2007 at 1:34 AM
I recommend that you don't use the ODBC drvier for SQL Server and instead use the Native SqlClient Driver.

The error has nothing to do with the DAAB. The code you have won't work with the ODBC Driver.

Look at the examples here:

The configuration information in app.config tells the DatabaseFactory.CreateDatabase() method the database you are connecting to and the database class to use to connect to that database.

Check the documentation and the quickstarts for examples. I have a tutorial here that may help:

and all of my Enterprise Library 2.0 Tutorials here:




David Hayden
Microsoft MVP C#