Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0DAL+ - extra database connectionDAL+ - extra database connection
Previous
 
Next
New Post
1/20/2007 5:34 PM
 

I'll make a Blog post and post some sample code, but basically connecting to another database appears to be straightforward

(you have to have Imports Microsoft.ApplicationBlocks.Data at the top of the page)

Dim ConnectionString As String = "Server=(local);Database=Northwind;uid=myusername;pwd=mypassword;"
Dim mySqlString As StringBuilder = New StringBuilder
mySqlString.Append(
"SELECT * ")
mySqlString.Append(
"FROM Customers ")
Dim myreader As IDataReader
myreader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text, mySqlString.ToString)

GridView1.DataSource = myreader
GridView1.DataBind()
 

We don't need "DotNetNuke.Data.DataProvider.Instance().ExecuteReader(..." because we don't care about the current "instance" of the provider that DotNetNuke is currently running on. Normally "Instance()" would return the current data provider that DotNetNuke is currently using (for example it could be MS SQL Server, Oracle or MySQL) but in this case we KNOW what database we want to connect to (a database that is NOT the current instance).

The only thing the DAL+ does is provide a way to get to the database with the least amount of code. With the DAL+ you can call the database with one line of code such as:

CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString()), IDataReader

In the example above I am also using one line:

SqlHelper.ExecuteReader(ConnectionString, CommandType.Text, mySqlString.ToString())

Is this what you are looking for or am I missing a requirement? If not then I don't think we need a change to the Core because the current data provider contains methods for connecting to the current instance and here we are trying to connect to a database that is NOT the current instance so it doesn't seem like the proper place to put the code.

We would be creating an instance of the current provider to connect to another unrelated database. Plus, the code to connect to the alternate database ourselves is only one line :)



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
3/7/2007 4:21 PM
 

So Michael - you advocate just using the SqlHelper class then ?

maybe just holding those connection strings and stuff in web config or something then? 

 


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
3/7/2007 8:52 PM
 
famdylan wrote

So Michael - you advocate just using the SqlHelper class then ?

maybe just holding those connection strings and stuff in web config or something then? 

 

Yes, you can store the connection string in Module or Portal settings. See my post with sample code: Connecting to another database



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
3/13/2007 6:05 PM
 

Michael - okay I understand everything you are doing so far and i can easily store the connection string innthe web config or whatever I need to do - now my next question really has to do with stored proc parameters -

what is the best way to add them to the sqlhelper.executereader function ?

I see the overload is ParamArray of CommandParams or an object - I was looking at how DNN sort of does this and I dont think I understand it well enough

Do I need to tell my function that each function parameter is a parameter for the stored proc?


Dylan Barber http://www.braindice.com - Dotnetnuke development classes - skins and modules
 
New Post
3/13/2007 8:44 PM
 

Like this:

Public Shared Sub ThingsForSale_Insert(ByVal ThingsForSaleInfo As ThingsForSaleInfo)
    DataProvider.Instance().ExecuteNonQuery("ThingsForSale_Insert", ThingsForSaleInfo.ModuleId, GetNull(ThingsForSaleInfo.UserID), GetNull(ThingsForSaleInfo.Category.ToString), GetNull(ThingsForSaleInfo.Description.ToString), GetNull(ThingsForSaleInfo.Price))
End Sub

see:

http://www.adefwebserver.com/DotNetNukeHELP/DNN_Things4Sale/ThingsForSale2.htm

 



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0DAL+ - extra database connectionDAL+ - extra database connection


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out