[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

The type or namespace name 'DuplicateKeyException' could not be found (are you missing a using directive or an assembly reference?)

Posted on 2009-04-17
2
Medium Priority
?
586 Views
Last Modified: 2013-12-17
I am trying to catch duplicate records with this code but I am not sure why it is giving me this error message.  Can someone point me in the right direction?


private static void UpdateTable(ChartRelayDataClassDataContext db, Object record)
        {
 
 
            // Get the type of the record to insert
            string type = record.GetType().Name;
 
 
 
            // ---------------  Write PROVIDER_REFERRAL_QUEUE Record -------------------------
 
 
            if (type == "PROVIDER_REFERRAL_QUEUE")
            {
                
 
                db.PROVIDER_REFERRAL_QUEUEs.InsertOnSubmit(record as PROVIDER_REFERRAL_QUEUE);
 
                try
                {
                    // Attempt to update the database
                    Console.WriteLine(String.Format("About to Submit Changes for Treatment"));
                    db.SubmitChanges();
                    Console.WriteLine("No Duplicate Treatment Record");
 
                }
                catch (DuplicateKeyException duppatexc)------------------------ERROR OCCURS HERE --------------
                {
                    // This DuplicateKeyException is a Linq exception for duplicate keys that exist
                    // in the DataContect and not the database, reason why it was not catching it.
                    // Remove record from DataContext and continue.
                    switch (type)
                    {
 
                        case "PROVIDER_REFERRAL_QUEUE":
                            // Using exception object duppatexc to print the error message
                            Console.WriteLine("Duplicate Record in Memory Treatment\n" + duppatexc.Message);
 
                            db.PROVIDER_REFERRAL_QUEUEs.DeleteOnSubmit(record as PROVIDER_REFERRAL_QUEUE);
                            break;
                    }
 
                }
                catch (SqlException sqle)
                {
                    
                    // This is a duplicate record found in the databas, remove record fFamilym DataContext.
                    switch (type)
                    {
                        case "PROVIDER_REFERRAL_QUEUE":
                            Console.WriteLine("Duplicate Record in SQL Table Treatment\n" + sqle.Message);
                            db.PROVIDER_REFERRAL_QUEUEs.DeleteOnSubmit(record as PROVIDER_REFERRAL_QUEUE);
                            break;
                    }
                }

Open in new window

0
Comment
Question by:kwh3856
2 Comments
 
LVL 14

Accepted Solution

by:
amar31282 earned 2000 total points
ID: 24173707
Try using
 System.Data.Linq.DuplicateKeyException
0
 

Author Closing Comment

by:kwh3856
ID: 31571723
Thank you very much!!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question