Working with Multiple Databases

Data Access Application Blocks Forum

Working with Multiple Databases

Postby myuserid on Tue Jan 27, 2009 5:36 pm

Hi, I'm not sure if this is an EasyObjects question or a MyGeneration question or even a .Net question but I'll start here and focus on the EasyObjects part of it.

I'm working with an application that I would like to have access two different databases direclty via easy objects. My web.config file has two connection strings specified, one for each DB. I used MyGenerations to create EasyObjects and Sprocs for the required tables in each DB. The call to one DB is made from a custom page class that my webpage inherits. The other call is made directly from the page. The call from the page class works fine (it's using the default connection as specified in the web.config) but when trying to switch to a new connection and use the other database, I'm getting the infamous error "Object reference not set to an instance of an object" in the LoadAll function at this line

Return MyBase.LoadFromSql(Me.SchemaStoredProcedureWithSeparator & "daab_GetAllCategories", parameters, CommandType.StoredProcedure)

I think this is telling me that the Sproc doesn't exist which kind of indicates that I haven't correctly switched to the right connection. My call to easy objects looks something like this

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim c As New Categories 'This is the EasyObject
c.ConnectionString = ConfigurationManager.ConnectionStrings.Item("MyConnectionString").ToString()
c.LoadAll()

Me.RepeaterCategories.DataSource = c.DefaultView
Me.RepeaterCategories.DataBind()
End Sub

Both DB's are in the same Database Server instance on localhost. And the connection strings I'm using are correct and work in other situations. I'm sure I'm missing some important point here but have no idea what that would be. Any suggestions. Thank you very much.
myuserid
Lurker
 
Posts: 7
Joined: Fri Apr 27, 2007 7:50 pm

Re: Working with Multiple Databases

Postby mgnoonan on Sat Jan 31, 2009 8:52 pm

Answered via email:

Need to set the DatabaseInstanceName on the object to select one of the entries from the ConnectionStrings section in the config file.
Matt Noonan
EasyObjects.NET - The O/RM for the Enterprise Library
http://www.easyobjects.net
User avatar
mgnoonan
Expert
 
Posts: 1019
Joined: Tue Sep 14, 2004 3:17 am
Location: Springboro, OH


Return to EasyObjects.NET (Microsoft Enterprise Library)

Who is online

Users browsing this forum: No registered users and 1 guest