.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

HELP!!! UpdateException was unhandled by user code [System.Data.UpdateException]

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :ASP.Net
 

Hello,

I've got this error when trying to save a new row into a table with two PKFK fields.

This table is called tbl_TeamMatch and has the two PKFK fields TeamID and MatchID (which come from tbl_Team and tbl_Match tables, because these to tables have a many2many relationship) this table is being used as the bridge.

I am using an Entity Data model in Asp.net c#

UpdateException was unhandled by user code

{"Entities in 'CricketDBEntities2.tbl_TeamMatch' participate in the 'FK__tbl_TeamM__Match__5CD6CB2B' relationship. 0 related 'tbl_Match' were found. 1 'tbl_Match' is expected."}

Here's the code behind:

public partial class pgFixtures : System.Web.UI.Page
{
    CricketDBEntities2 db = new CricketDBEntities2(); //my database model object

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    private void InsertTeamMatch()
    {
        tbl_TeamMatch tm1 = new tbl_TeamMatch();
        tbl_TeamMatch tm2 = new tbl_TeamMatch();

        tm1.TeamID = Convert.ToInt32(clsS


View Complete Post


More Related Resource Links

System.Data.SqlClient.SqlException was unhandled by user code

  
System.Data.SqlClient.SqlException was unhandled by user code  Message=Incorrect syntax near '01'.Unclosed quotation mark after the character string ' from month_day where month_name=datename(month,dateadd(month,01,0)-1)'.  Source=.Net SqlClient Data Provider  ErrorCode=-2146232060   LineNumber=1  Number=102  Procedure=""  Server=W2003-VM1-MK  State=1  StackTrace:       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)       at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()       at System.Data.SqlClient.SqlDataReader.get_MetaData()       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)   &nbs

System.Data.SqlClient.SqlException: Login failed for user . Reason: The account is disable

  

Hi All,

Thank you for advance.

I created a widows service for mail schedule with c#.net and sql server 2005 and it is working fine for past one year.

now sometimes i am getting the "System.Data.SqlClient.SqlException: Login failed for user '<UserName>'. Reason: The account is disabled." error.

then i restarted the windows service manually and working.

what is the problem in my sql server connection and how to fix that issue?


what is the better design for location of system database data / log files and user data/log file,

  
is there a guideline for better performance for system database data location log location, like tempdb location etc. also better location for user databases/data and log.

Unhandled exception in XAML editor from control that accesses database. - "System.Data.SqlServerCe.S

  

Hello,

Im having a bit of difficulty with some WPF/C#/SQL Server CE code.

I have a WPF User Control with the following line of code in the constructor:

MyDatabase database = new
 MyDatabase("Data Source=|DataDirectory|\\MyDatabase.sdf"
 );

where MyDatabase is a class generated using SQLMetal.exe from MyDatabase.sdf.

 

When I added this control to other controls, the application runs fine and I'm able to access my database. When I try to edit these parent controls,  the XAML editor throws the following error:

 

>System.Data.SqlServerCe.SqlCeException
>The database file cannot be found. Check the path to the database. [ Data Source = D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MyDatabase.sdf ]

 

Why does the XAML editor redirect my DataDirectory to "D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\" and why does the XAML editor execute my database access code?

 

How can I fix this so I can use this control in a XAML editor?

Thanks,

Greg S.

 


Unhandled exception in XAML editor from control that accesses database. - "System.Data.SqlServerCe.S

  

Hello,

Im having a bit of difficulty with some WPF/C#/SQL Server CE code.

I have a WPF User Control with the following line of code in the constructor:

MyDatabase database = new
 MyDatabase("Data Source=|DataDirectory|\\MyDatabase.sdf"
 );

where MyDatabase is a class generated using SQLMetal.exe from MyDatabase.sdf.

 

When I added this control to other controls, the application runs fine and I'm able to access my database. When I try to edit these parent controls,  the XAML editor throws the following error:

 

>System.Data.SqlServerCe.SqlCeException
>The database file cannot be found. Check the path to the database. [ Data Source = D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MyDatabase.sdf ]

 

Why does the XAML editor redirect my DataDirectory to "D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\" and why does the XAML editor execute my database access code?

 

How can I fix this so I can use this control in a XAML editor?

Thanks,

Greg S.

 


Unhandled Exception in System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

  

Hi,

I have a windows service app which has been running for days now perfectly well, but last night it stopped.

The service app is built using .Net 4 Framework Client Profile with a dll built with .Net 4 Framework (why the difference I can't be sure now !!).

The app is running on Windows 2008 Server and connects to a local SqlExpress 2008 R2.

My call to System.Data.SqlClient.SqlCommand.ExecuteNonQuery() is wrapped in a try/catch but did NOT get caught !! :

The C# function being called (within my dll from a wrapper function) is :

 

 

private

nullreferenceexception was unhandled by user code

  

Im having a problem here...The idea is,each user will have their own username and password that will be verified together with the userType from the user database.(eg: Admin, User,Clinicians etc)....this will then lead to individual pages with their respective navigation bars attached to the page....somehow i can get the user to Admin to work but not the rest.Here are the codes.... need help urgently!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TeleCare : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        //if (HttpContext.Current.User.Identity.IsAuthenticated)
        //{
        //    Users user;

        //    if (Session["Users"] == null)
        //    {
        //        Session["Users"] = Users.(HttpContext.Current.User.Identity.Name);
        //    }

           //user = (Login1_Authenticate)Session["Users"];


        //   }
        //}

        if (string.Compare(Session["UserType"].ToString(), "Admin", true) == 0) >>>My error is here
        {
            if (e.Item.Text == "Home" 

CommunicationException was unhandled by user code;The remote server returned an error: NotFound

  
Hi ,

Getting an err :CommunicationException was unhandled by user code;The remote server returned an error: NotFound.

scenario:

1. we are sending large amount of data from Silverlight client to wcf svc and storing in DB.
2. when the data size is less its working fine.
3. But when we send large data we get an err like

CommunicationException was unhandled by user code

The remote server returned an error: NotFound

4. we also increased the Buffer Sizes in the binding part in the config files.


most of the google results , forums are saying to increase the Buffer Sizes, but still we face the same proble.


Any clues on how to overcome this err will be a gr8 help!

Thanks
Senthil

http://dotnetcrunch.blogspot.com


Linq - add data to database then email user the details

  

Hi all

I'm not sure how to structure the code for this but what I want to do is be able to add data to a database, and once this has completed successfully, then email the user to say the details have been added successfully to the database.

I need to:

1. Check that the relevant data has been added into the database then

2. Email the details of the relevant data when completed. 

 

Thanks in advance for your help,

Laura

 

 


logged in user data

  

I'm using the defualt membership provider, i created a table and used the gridview on the logged in user page to show his information such as address e-mail phone zip code etc,, how can i do this without writing a code?


I am new to asp.net  i need simple help please?



Storing User Data

  

Hello,

I'm trying to get the current logged in UserId Value, using this code


Protected Sub UserProfileDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles UserProfileDataSource.Selecting      ' Get a reference to the currently logged on user      Dim currentUser As MembershipUser = Membership.GetUser()      ' Determine the currently logged on user's UserId value      Dim currentUserId As Guid = CType(currentUser.ProviderUserKey, Guid)      ' Assign the currently logged on user's UserId to the @UserId parameter      e.Command.Parameters("@UserId").Value = currentUserId End Sub


But, I getting an error (NullReferenceException), I did set a url authorization on the page that i try to get the logged in user information, witch is info.aspx, and I made the login.aspx control to be redirected to the info.aspx after the login process, But the info.aspx  only shows me (access in denied), how can i make this page knows that i am already logged in?




The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must

  

Hi,

This is frustrating, and I don't know how to solve it.

I have a strange problem. I am adding a LinqDatasource object, and set the context:

        protected void LinqDataSource_ContextCreating(object sender, LinqDataSourceContextEventArgs e)
        {
            e.ObjectInstance = new KaruselaDataContext(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        }


Then I get this error:
The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

 

On web.config I already have this:
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

NOTE: The datacontext is in a different project (DLL proect) where I added a refernce to System.Data.Linq.

is there another way adding a refernce to a web project? or only though teh web.config?

Thanks.


Persist data in a dynamically populated ListBox in a user control

  

Hi All,

I am trying to persist data in a dynamically populated ListBox in a user control. Here are the details

I have a user control which contains a a listBox and button. On Page_Load of user control I am populating the ListBox control with some values. On Click of button, I am trying to fetch the values which I have selected in ListBox. Though this seems very simple and straight forward I am unable to fetch values.

My Page_Load Function

void Page_Load(object sender, EventArgs e)

{

       If(!IspostBack)

        {

              listBox.items.Add("Item1");

             listBox.items.Add("item2");

             listBox.items.Add("item3");

         }

}

 

My Click Function

Protected Void Button1_Click(object sender, EventArgs e)

{

       string strValue = listBox.SelectedValue

}

 

I have placed brake point at Page_Load and on click function, I am seeing that the moment the breakpoin

Toolbox: Data Snapshots, Subversion, Source Code Organization and More

  

If you want to save, organize, and annotate snapshots of your database data, find an easy way to install and configure Subversion, and automate the organization of your source code, then you'll want to read more about these latest tools.

Scott Mitchell

MSDN Magazine August 2009


Under the Table: How Data Access Code Affects Database Performance

  

In this article, the author delves into some commonly used ways of writing data access code and looks at the effect they can have on performance.

Bob Beauchemin

MSDN Magazine August 2009


Smart Storage: Protect Your Data Via Managed Code And The Windows Vista Smart Card APIs

  

Smart cards are a compelling alternative to the reliance on passwords, which are the weakest link in authentication systems. Get the Windows smart card programming basics here.

Dan Griffin

MSDN Magazine November 2006


Data Points: Revisiting System.Transactions

  

The System.Transactions namespace of the Microsoft .NET Framework makes handling transactions much simpler than previous techniques. Read all about it this month.

John Papa

MSDN Magazine November 2006


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend