Newbie problem using data access blocks

Topics: Logging Application Block
Oct 31, 2007 at 8:17 PM
Hi all,

I have used the old version of the Microsoft data application blocks for years. But a client wants to use the 3.1 version of the enterprise library as it's now called. I have had nothing but problems. I downloaded the files and thought I built everything correctly. I can run the quick start examples and they all run fine so I assume I have this all configured properly. I then decided to test this with some of my own code. Here is what I did:

- In my business logic layer, I chose a simple class and created this function which returns a dataset:

Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Public Class CreditCardType
Public Function GetCreditCardType() As DataSet
Dim db As Database = DatabaseFactory.CreateDatabase()
Return db.ExecuteDataSet(mstrDBConnectionString, "GetCreditCardTypes")
End Function
End Class

With the old data blocks I would use:

Return SqlHelper.ExecuteDataset(mstrDBConnectionString, "GetCreditCardTypes")

On my web page, I want to bind a gridview to this dataset. So I have the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objCreditCardType As New TestProject.CreditCardType(connString)
gv.DataSource = objCreditCardType.GetCreditCardType()
gv.DataBind()
End Sub
When I run this, I get an error on this line:
Dim db As Database = DatabaseFactory.CreateDatabase()

I get this error:
NullReferenceException was unhandled by user code.
I have no idea what I did wrong. I keep reading about some configuration tools within this new enterprise library 3.1 but do not know how to run them. The old microsoft application data blocks was such an easy thing to set-up. Just download, build the project, and then add a reference to your business logic layer and you were off and running. I'm on my second day of fooling around with this new and improved version and still cannot get anything working!

Any help would be appreciated!

Thanks,
Bob
Oct 31, 2007 at 9:20 PM
Hi,

The DAAB's factory is configuration driven, so you need to provide appropriate appropriate config. Or, if you want to use a configuration free approach you can do something like Dim db As Database = New SqlDatabase(mstrDBConnectionString).

Fernando