Click here to Skip to main content
15,889,861 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi All ,

I was tried to work with wcf service using singleton pattern getting error


C#
'System.Data.Linq.DataContext' does not contain a constructor that takes 0 arguments


can u guide how to solve this error ,


C#
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Linq.Mapping;
using System.Data.Linq;
using System.Reflection;
namespace WcfService5
{
   
    public class Singleton : DataContext
    {
        private static Singleton _instance = null;

        private static Object _mutex = new Object();
        static String connection;
        private Singleton(String connectionString)
        {
            // whatever
        }

        public static Singleton GetInstance(String ConnectionString)
        {
            if (_instance == null)
            {
                lock (_mutex) // now I can claim some form of thread safety...
                {
                    if (_instance == null)
                    {
                        _instance = new Singleton(ConnectionString);
                    }
                }
            }

            return _instance;
        }
        [Function(Name = @"GetEmpByNames", IsComposable = false)]
        public ISingleResult<myems> getCustomerAll([Parameter(DbType = "Nvarchar(50)")] string Ename, [Parameter(DbType = "Int")] Int32 Eno)
        {

            IExecuteResult objResult = this.ExecuteMethodCall(this, (MethodInfo)MethodInfo.GetCurrentMethod(), Ename, Eno);
            ISingleResult<myems> objresults = (ISingleResult<myems>)objResult.ReturnValue;
            return objresults;
        }
    }  
   
}
Posted
Updated 21-Nov-13 1:39am
v2
Comments
Er Daljeet Singh 21-Nov-13 4:48am    
just do one thing in Singleton class where you have created a parameterised constructor before calling it call the base class construstor means you have to implement constructor chaining here is the syntax

Singleton(String connectionString):base(connectionString)
{
// whatever
}

Your constructors need

... : base({arguments the base class constructor wants})


after the declaration line. Without this, C# tries to initialize the base class using a constructor with no arguments and you can see from the error that there is no such constructor in the base class.

Good Luck
 
Share this answer
 
try this code...

C#
public Singleton(String connectionString): base(connectionString)
       {
           // whatever
       }



Make the constructor access modifiers as public
and initiate base class with the connectionstring in the base class constructor..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900