0

I'm running this code where basically I have a stored procedure which is inserting a new row into the table member. I have posted the code of the method from C# to call the stored procedure and the code where I'm calling that method:

Stored procedure:

[AutoComplete(true)]
public void AddNewMember(Member cm)
{
   SqlCommand cmd = new SqlCommand();
   SqlDataAdapter da = new SqlDataAdapter();

   try
   {
       this.Connection.BeginTransaction();

       this.InitializeConnection();

       cmd = new SqlCommand("sp_addNewMember", this.Connection);
       cmd.Parameters.Add(new SqlParameter("@memberID", cm.MemberID));
       cmd.Parameters.Add(new SqlParameter("@userID", cm.UserID));
       cmd.Parameters.Add(new SqlParameter("@dateJoined", cm.DateJoined));
       cmd.Parameters.Add(new SqlParameter("@Duties", cm.Duties));

       cmd.CommandType = CommandType.StoredProcedure;

       da.InsertCommand = cmd;

       ContextUtil.SetComplete();
    }
    catch (Exception ex)
    {
        ContextUtil.SetAbort();
    }

Calling the method:

DataLayer.Member cm = new DataLayer.Member();
cm.MemberID = Guid.NewGuid();
cm.UserID = new Guid(txtUserID.Text);
cm.DateJoined = Convert.ToDateTime(txtDateJoined.Text);
cm.Duties = txtDuties.Text;

DataLayer.AddMember acm = new DataLayer.AddMember();
acm.AddNewMember(cm); 

Exception that gets thrown on the acm.AddNewMember() line:

System.Runtime.Serialization.SerializationException: Unable to find assembly 'DataLayer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=536d0c71bd79a82e'

Do someone know what the problem is please?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Xupla
  • 201
  • 2
  • 4
  • 14
  • The main question is: **why** would you write a stored procedure to insert a data row in C# - this should be in T-SQL - that's what T-SQL is really good at, and what T-SQL excels at – marc_s May 15 '12 at 08:04
  • have you added the assembly `Datalayer` to the references of your project and defined it in using section? – webber2k6 May 15 '12 at 08:05
  • @marc_s: with a procedure you can check constraints and correctness of parameters, so i think it is a good approach. – webber2k6 May 15 '12 at 08:07
  • @webber2k6: a T-SQL stored procedure **also** checks for parameters, constraints etc. - no difference here (and no benefit for the SQL-CLR approach ...) – marc_s May 15 '12 at 08:09
  • yes I have added the reference to the project. – Xupla May 15 '12 at 08:17

2 Answers2

0

You need to look inside the InnerException of the exception and also "Detail" of the exception. Strip the code down into only the insert data portion. I don't know what the ContextUtil does. Saving data to sql server shouldn't require serialization. I think it is other stuff in the function that doing serialization.

iefpw
  • 6,816
  • 15
  • 55
  • 79
0

It looks to me like configuration problem. Your code doesn't help much.

I guess DataLayer is Your class somewhere in your DataLayer.dll. Where is this code invoked? On Web service? Where do You get Your exception? On client application?

If so then You might be getting entirely different exception and this is just a problem with sending it to client app.

Grzegorz W
  • 3,487
  • 1
  • 21
  • 21