Reputation: 87
This is my DBML Designer Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
public partial class DataClassesDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
#endregion
public DataClassesDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClassesDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClassesDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public DataClassesDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
}
this is my C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cmdLogin_Click(object sender, EventArgs e)
{
DataClassesDataContext db = new DataClassesDataContext();
}
}
when i write the DataClassesDataContex db=new DataClassesDataContex(); it will show DataClassesDataContex does not contain a constructor that takes 0 arguments?
Upvotes: 1
Views: 9968
Reputation: 119
The problem is that the Connection setting in the Properties window got removed.
To see these properties
See in the previously attached image that the Connection property got removed. If you can't readd the Connection, you can revert your source control to a previous history point and just re-add the tables and settings since your last commit.
Problem fixed!
The default constructor in .designer.cs got restored.
public DataClassesHelpTicketsDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["Help_TicketsConnectionString1"].ConnectionString, mappingSource)
{
OnCreated();
}
Upvotes: 0
Reputation: 113
Steps:
Upvotes: 4
Reputation: 159
I fixed it with these steps:
Remove:
<connectionString>
<add name="exampleDB" connectionString="Data Source=example;Initial
Catalog=example;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Remove:
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=D...8"/>
</assemblies>
You can find <assemblies>
within <compilation></compilation>
If you have more than one <add assembly />
tag, you have more than one connection to DB.
Add another "example.dbml" add your tables again.
Create a new datacontext object.
Upvotes: 0
Reputation: 236218
There is no parameterless constructor defined in your class DataClassesDataContext
. By default there should be another constructor generated, which gets connection string from application settings:
public DataClassesDataContext() :
base(global::Foo.Properties.Settings.Default.BarConnectionString,
mappingSource)
{
OnCreated();
}
But for some reason it is missing right now. You can:
DataClassesDataContext
and add parameterless constructor manuallyUpvotes: 9