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.0working with multiple databasesworking with multiple databases
Previous
 
Next
New Post
4/4/2007 10:58 AM
 

Besides the DNN database, I need to create a module that connects to a different database to pull information for display.

Can I create an additional connection string in the web.config that can be called for the module to connect?

If so, can I and how do I us the DNN infrastructure to make the call to the other database from within the module (as opposed to writing straight ADO.NET code)?

Thanks,

Hal

 
New Post
4/4/2007 11:48 AM
 

I think you'd be better off doing straight ado.net code to call your other database as DNN is pretty much setup to pull information from the default dataprovider, and you're basically looking to call a different provider.

Perhaps someone else will have a better suggestion, but that is how I would start


Chris Hammond
Former DNN Corp Employee, MVP, Core Team Member, Trustee
Christoc.com Software Solutions DotNetNuke Module Development, Upgrades and consulting.
dnnCHAT.com a chat room for DotNetNuke discussions
 
New Post
4/4/2007 12:45 PM
 

Yes, you can specify it in the webconfig and in the dataprovider and sqldataprovider, make sure you change it to point to the new configuration.

Below I changed the default "Data" to point to a new config called "applicationData"

SqlDataProvider File
Private Const ProviderType As String = "applicationData"

DataProvider File
' dynamically create provider
Private Shared Sub CreateProvider()
objProvider = CType(Framework.Reflection.CreateObject("applicationData", "NamespaceGoesHere", ""), DataProvider)
End Sub

WebConfig File
<sectionGroup name="dotnetnuke">
<section name="data" requirePermission="false" type="DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke"/>
<section name="applicationData" requirePermission="false" type="DotNetNuke.Framework.Providers.ProviderConfigurationHandler, DotNetNuke"/>

...

<connectionStrings>
<add name="SiteSqlServer" connectionString="..." providerName="System.Data.SqlClient"/>
<!-- Connection String for SQL Server 2000/2005 -->
<add name="applicationData" connectionString="New Connection String Goes Here" providerName="System.Data.SqlClient"/>

...

<appSettings>
<!-- Connection String for SQL Server 2005 Express - kept for backwards compatability - legacy modules -->
<add key="SiteSqlServer" value="..."/>
<!-- Connection String for SQL Server 2000/2005 - kept for backwards compatability - legacy modules-->
<add key="applicationData" value="New Connection String Goes Here"/>

...

<dotnetnuke>
<!--ApplicationDatabase Provider-->
<applicationData defaultProvider="SqlDataProvider">
<providers>
<clear/>
<add name="SqlDataProvider" type="DotNetNuke.Data.SqlDataProvider, DotNetNuke.SqlDataProvider" connectionStringName="applicationData" upgradeConnectionString="" providerPath="~\Providers\DataProviders\SqlDataProvider\" objectQualifier="" databaseOwner="dbo"/>
</providers>
</applicationData>

...

 
New Post
4/4/2007 1:33 PM
 

Another option I've been playing with lately and seems to work nicely is the new data objects in ADO.Net 2.0, available obviously with ASP.Net 2.0 and Visual Studio 2005.  Note that if you are dealing with new tables, even in the DNN's own database, there is not much of a "DNN Infrastructure" to help you, as far as DAL components.  You would have to create it.  For that reason is that you need to consider the two approaches below.  To be honest, for my modules I have not created the full DAL architecture for data access but I do try to use Stored Procs for all data access.

Anyway, after adding the new connection string to the Web.config, you can go to VS2005 and create a "SQLDataSource" that other controls on the page can use.  You just define the connection string like this:

"<%$ ConnectionStrings:SiteSqlServer %>" for the default connection, or "<%$ ConnectionStrings:YourNewString %>" for a new string to a second database. 

All the power of ADO.Net 2.0 and its integration with VS 2005 is now at your hands and you can use all those articles you read about in various ASP.Net sites.  This is what I like the most, data access becomes "standardized" and I now have more resources at my disposal.  I started testing this with a GridView and it can do paging and sorting with no code in a DNN module, really amazing.  And let me tell you that I was skeptical at the beginning as I like to code all the data access by hand and not use the graphical interface to do it.  The implementation in ADO.Net 2.0 and VS 2005 is a lot cleaner than what it was in 1.1.

Bear in mind that all the nice features work by default with Datasets, if you want to optimize and use Datareaders then you would have to do coding by hand.  This may or may not be an issue for your site/app.

You can always do data access with the DAL+ as described by Michael Washington here: http://www.adefwebserver.com/DotNetNukeHELP.

Carlos

 

 
New Post
4/4/2007 4:27 PM
 

Is the other database you want to connect to in the same sql server instance?  If so, you can use straight sql syntax to explicitly call the desired database.

In your stored proc, just reference the other database.  This assumes the other data you need is on the same server as your dnn database, but it does not need to be the same database.  Something like this...

SELECT
    'username' = u.username,
    'firstname' = u.firstname,
    'lastname' = u.lastname,
    'hiredate' = e.hiredate,
    'department' = e.department,
    'jobcode' = j.jobcode
FROM dotnetnuke.dbo.users U
JOIN companydb.dbo.employees E ON e.employeeid = u.username
JOIN hrdb.dbo.jobcodes J ON j.employeeid = e.employeeid
WHERE u.username = @username

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0working with multiple databasesworking with multiple databases


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