Tuesday, March 20, 2012

Accessing 2 databases on the SQL server through ASP.net

Hi everyone,

First of all I'd like to say I'm new to the forums, and in fact new to ASP.net.

I've had a couple of applications running in VB.net for the last year or so that I now am looking to move on and into ASP.net (main reason is to do with implementation to remote sites in foreign countries).

I'm currently following through the "Working with data and ASP.net 2.0" walkthrough on this site, which I must say has been a great help.

I'll start with the background stuff firstSmile

I have my main database on an SQL server. I also have 2 other databases on there - Customer and Employee. The reason for these are that they are shared amongst my VB applications and I kept them as seperate databases so that one database is all that needs to be administered and maintained, and these changes are then seen on both apps (takes away redundant data as well).

In my main database, main table, is a field called CustomerID. This value relates to the CustomerID in the Customer table. In my VB app all I do is have the user select a customer name, and then the customer ID value is copied to the CustomerID field of my main table when inserting / updating a row. This is simply accomplished with 2 SQL connections and 2 dataAdapters. I also use 2 dataSets - one for Customer, one for WorkRequests (the main database)...

I use ComponentOne stuff so that my grid will show the CustomerName instead of the CustomerID etc, and the same applies when I use my Employee database - I run many dataAdapters to this for things such as Account Manager, Technologist, Creator, UpdatedBy etc etc.

Now, I'm new to VS 2005 - my apps were created in VS 2003 and .net 1.1. Can I easily re-create my apps in ASP.net? My primary goal at the moment is to make sure I can load a row, and display the "lookup" values instead of the "integer" value. As my tables are in seperate databases, I would like to know the best way of accomplishing this, if it is of course possible.

Help and advice much appriciated.

Kind Regards,

Luke

SQL supports 4-section object name, in?the?format?of?server.database.owner_name.object_name,?so?just?add?database?part?when?you?want?to?refer?to?object?in?other?database.?For?more?information,?please?refer?to:?Using Identifiers as Object Names|||

Thank you very much, you reminded me about that, I think I looked into it ages ago but then put it to the back of my mind.

To display my CustomerName field by linking to the CustomerID field I'm using;

SELECT npd_dwr.dbo.dwr.dwrnumber, npd_dwr.dbo.dwr.customerid, customerdb.dbo.customer.customername
FROM npd_dwr.dbo.dwr
INNER JOIN customerdb.dbo.customer ON npd_dwr.dbo.dwr.customerid = customerdb.dbo.customer.customerid

Thanks again,

Regards

No comments:

Post a Comment