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

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulestwo modules connecting to external databasetwo modules connecting to external database
Previous
 
Next
New Post
3/28/2013 2:16 PM
 

 Hello, I'm getting an error in my Data Service from the following line:
return new Data.sistersDBEntities(new EntityConnection(DataCache.GetCache(STR_BirthdaySister_EF_ConnectionString_Key).ToString()));
Error: DotNetNuke.Modules.SistersBirthdays.Data.sistersDBEntities' does not contain a constructor that takes 1 arguments
Here's my full Data Service (based on Steve Fabians demo)
Background: (dnn7.00.04, VS 2010, IIS7.5) I have one module (works fine) that connects to our SQL server using the same data service code. This second module connects to the same database. Here's the full DS code:
//------------------------------------------------------------------------------
// <copyright file="WebDataService.svc.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
using DotNetNuke.Services.Localization;
using System.Data.SqlClient;
using System.Configuration;
using System.Data.EntityClient;
using DotNetNuke.Common.Utilities;

namespace DotNetNuke.Modules.SistersBirthdays.Service
{
    [System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class SistersBirthdaysDataService : DataService< Data.sistersDBEntities >
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.UseVerboseErrors = true;
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }
        
        protected override Data.sistersDBEntities CreateDataSource()
        {
            return CreateModuleDataSource();
        }

        [WebGet]
        public string GetVersion()
        {
            var ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            return String.Format("{0}.{1}.{2}.{3}",
                ver.Major, ver.Minor, ver.Build, ver.Revision);
        }

        [WebGet]
        public string GetResourceString(string key)
        {
            return Localization.GetString(key, "/DesktopModules/BirthdaySister/Views/App_LocalResources/SharedResources.resx");
        }

        private Data.sistersDBEntities CreateModuleDataSource()
        {
            try
            {
                // first check the cache, we only want to do this once
                const string STR_BirthdaySister_EF_ConnectionString_Key = "BirthdaySister_EF_ConnectionString_Key";

                //if (DataCache.GetCache(STR_BirthdaySister_EF_ConnectionString_Key) == null)
                //{
                // if not in the cache, construct the entity connection and cache it
                using (var SiteSQLConnection = new SqlConnection(
                    ConfigurationManager.ConnectionStrings["sistersDBEntities"].ConnectionString))
                {
                    //check if the connection string has integrated security enabled
                    {
                        bool isIntergratedEnabled = SiteSQLConnection.ConnectionString.Contains("Integrated Security");

                        //Build the Entity Framework connection string from the derived settings
                        var NewSQLConnectionString = new SqlConnectionStringBuilder();
                        var _with1 = NewSQLConnectionString;
                        _with1.DataSource = SiteSQLConnection.DataSource;
                        _with1.InitialCatalog = SiteSQLConnection.Database;
                        if (!isIntergratedEnabled)
                        {
                            string _uid, _pwd = string.Empty;
                            GetUserCredentialsFromConfigFile(SiteSQLConnection.ConnectionString, out _uid, out _pwd);
                            _with1.UserID = _uid;
                            _with1.Password = _pwd;
                        }
                        else
                        {
                            _with1.IntegratedSecurity = isIntergratedEnabled;
                            //.UserInstance = True
                        }
                        _with1.MultipleActiveResultSets = true;

                        var EFConnectionStringBuilder = new EntityConnectionStringBuilder();
                        var _with2 = EFConnectionStringBuilder;
                        _with2.Provider = "System.Data.SqlClient";
                        _with2.ProviderConnectionString = NewSQLConnectionString.ToString();
                        _with2.Metadata = "res://*/Data.SistersBirthdayModel.csdl|res://*/Data.SistersBirthdayModel.ssdl|res://*/Data.SistersBirthdayModel.msl";

                        DataCache.SetCache(STR_BirthdaySister_EF_ConnectionString_Key, EFConnectionStringBuilder.ToString());
                    }

                }
                //}

                // now establish the connection from the cache
                return new Data.sistersDBEntities(new EntityConnection(DataCache.GetCache(STR_BirthdaySister_EF_ConnectionString_Key).ToString()));
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }

        }

        private static void GetUserCredentialsFromConfigFile(string strConn, out string userid, out string password)
        {
            var s = new SqlConnectionStringBuilder(strConn);
            userid = s.UserID;
            password = s.Password;
            return;
        }
    }
}


 
New Post
4/3/2013 1:18 PM
 
Well I've my modules working individually, but they won't work on the same page. Each module is using the one - same connection string in the web.config. Is that why they don't work on the same page?
 
New Post
4/3/2013 2:37 PM
 
Jeff Frick wrote:
Each module is using the one - same connection string in the web.config. Is that why they don't work on the same page?

I don't know what your problem is but I doubt that is it.  I have multiple modules, same page, all connecting to the same DB. No problem.

 


Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
New Post
4/3/2013 3:23 PM
 
Thanks Richard - that's encouraging!
May I ask if your database is an external db and do you use the same Entity Container Name? That's what I'm doing, same container name with different model names. I'm a newbie and trying to learning on the fly, so any tips will help.
My modules use OData and KnockoutJS and a data service like the one above and the error I get is a binding error from the knockout script. (like I said before - all the modules working fine on their owe page) So I'm hoping I can do something that forces the script to load as a separate instance (if that makes any since).
 
New Post
4/3/2013 3:30 PM
 
Yes and yes.

I don't bother with OData, services or Knockout.

I didn't realize you had any error message from Knockout, you didn't say. I don't know anything about that. It may be that both modules include the Knockout script and it doesn't like being included twice.

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulestwo modules connecting to external databasetwo modules connecting to external database


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