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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Why do I get a duplicate key error on the following?

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :Sql Server
        var querymax = (from obj in EMAL_db.tObjects
                select (int?)obj.Id).Max();
        if (querymax != null)
          nextObjectId = (int)querymax + 1;
        newObject = new tObject();
        newObject.Id = nextObjectId++;
        catch (Exception ex0)
          MessageBox.Show("Exception in Converter.Execute " + ex0.Message + Environment.NewLine + ex0.StackTrace);

After unsuccessful attempts to insert into the database, ID's are consumed so that next to be inserted can be i.e. 143 when ...Max() returns 119. Why is that?

View Complete Post

More Related Resource Links

Duplicate columns names not allowed - OPENQUERY - OPENROWSET - Error 492

I have a piece of code below which manipulates incoming XML. I understand why it is failing in SQL2005, due to the duplicate name "Process". What i dont understand is why this works fine in SQL2000? We are trying to migrate from SQL2000 to SQL2005 and even if we run SQL2005 in 8.0 compatibility mode we still get the error. Why does it work in SQL2000 and is there anyway to emulate this behaviour in SQL2005? I really do not want to work through +-600 SPs to see if I need to change anything. Thank You declare @Event varchar(255) declare @XML varchar(3000) set @event = '' set @xml = '<OmegaEvent Process="NEWBUSINESS" Type="APPFORM" DateTimeStamp="2010-09-02T06:06:43" Version="3.0"> <APPFORM> <BUSSUNIT>AN</BUSSUNIT> <CATEGORYDESC> </CATEGORYDESC> <CHECKDIGIT>B</CHECKDIGIT> <CLIENTSTATUS> </CLIENTSTATUS> <CONVERSION> </CONVERSION> <DISTRCHANNEL> </DISTRCHANNEL> <EVENTDATE>20100902</EVENTDATE> <EVENTTIME>60643528960</EVENTTIME> <FINALISOR>N</FINALISOR> <FORM>MIFU</FORM> <FORMNAME>MAX INCOME COMPULSORY</FORMNAME> <INTERMEDCODE> </INTERMEDCODE> <MAIL_CAMPAIGN> </MAIL_CAMPAIGN> <POLICYNO>016058558</POLICYNO> <PROCESS>ICC</PROCESS> <PR

Duplicate column error in script

Hello, I have a new database server and I created a new database and now I'm trying to run a script that's supposed to create all the tables from the previous database server. The script is an accumulation of various changes I have made to the old database since the start of the project in order to implement a variety of features, so it has this pattern: ALTER TABLE X DROP COLUMN Y; GO and later in the file: ALTER TABLE X ADD Y int NOT NULL; GO When I run the script, I get a duplicate column error message for the table and field, although I first dropped the column and then added it again. I suppose I have to do some kind of flash after the drop and before the add, but isn't the GO supposed to do that? If not, how can I flash it in the script? Thanks.  

Foreign characters causing a duplicate attribute key error - how to avoid?

Greetings, We have a data warehouse into which we import data obtained from our outside vendors.  The data are then used to build data cubes.  Lately we have started to get a duplicate key error on the "County" attribute in our "Location" dimension.  The problem appears to be caused by these two values returned by the query that returns the distinct list of counties: Spree-Neisse Spree-Neiße These are German counties and they are really the same county, I believe.  Our data warehouse stores County as a varchar.  If I cast the stored value as nvarchar, the query that returns the distinct list of counties returns only the 2nd value and so should avoid the duplicate key error.  (I haven't tried it yet, just speculating.) This post suggests the root cause of the problem: http://ssas-musings.blogspot.com/2009/11/duplicate-key-error.html We don't have any control over the data before our vendors give it to us, and it comes from all over the world.  What is the best way to avoid occurrences of the duplicate attribute key error?  Should we be storing all our character data as nvarchar?  Would it be enough to cast the stored data as nvarchar when the cubes are being built?  Is there a better approach?  I'd like to get an idea of what the best practice would be.  Our warehouse

Master Detail-Modal Popup Duplicate Component ID error

This is my main page in which I have collapsible panel and my phone gridview is contained in it. The Initial page loads up properly and shows the gridview. All the errors happen when I select a gridview row for modal popup edit. I get the following errors one after other after ignoring each one of them. I have been struggling with his for almost a week. I would appreciate if someone could help me get rid of these errors. Following are the sections of the main page and the code in the gridview ascx control . Main GridView User Control Page.<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/basemaster.master" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <%@ Register TagPrefix="ucophone" TagName="ucopsphone" Src="~/UserControls/online_app_phone_gv.ascx" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:CollapsiblePanelExtender ID="CollapsiblePanelExtenderPhone" runat="server" TargetControlID="PanelContentPhone" Supp

Duplicate field name error, creating new site from custom template

I've made a site that maps the site (with a table of contents) and i export it to another site collection. I'm able to install and activate the solution in the other site collection, however when i'm going to create a new site using the site i've installed as a template it pops an error saying "A duplicate field name Wiki_x0020_Page_x0020_CategoriesTaxHTField" was found." I have no clue what this means. Can anyone help me? Thanks in advance

Error occurred in deployment step 'Activate Features': A duplicate field name "OrganizationTaxHTFi



Trying to deploy a feature to a Content Type Hub site with three Content types and about 15 fields. I have two managed meta data fields that is part of the base Content Type that I "connect" with the meta data store with a feature receiver. Now, first time I deploy it (from VS 2010) it works fine but if I retract and then to do it again I get the follwing error message,

Error occurred in deployment step 'Activate Features': A duplicate field name "OrganizationTaxHTField1" was found.

(The field name "OrganizationTaxHTField1" is the name of one of the Note fields. My understanding is that you need a corresponding Note field to each Taxonomy Field, or?)

Anyone knows whats wrong and have a solution? To me it looks like the field doesn't gets removed when I retract but I can't find the field. Have checked the UI, the hidden meta data list and in SP Manager.






"Duplicate content type name" error when trying to create a site from a custom site template


I am getting "A duplication content type name 'Approval' was found" error, when I try to create a new site based on a custom template.  These are the steps that result in the error:

  1. Create a new blank site.
  2. Without making any changes, save the blank site as a site template called "test".
  3. Try to create a new site based on the "test" template.
  4. Get the above error.

I did notice that when I tried creating site from the template in a different area of my site collection, the error name changed from "Approval" to "Requestor". 

As it stands I cannot use custom templates in my site collection.  Any advice on how to overcome this error?


IsapiModule Error 500 Issue


I am about exhausted trying to figure out this error:

HTTP Error 500.0 - Internal Server Error

Description: The page cannot be displayed because an internal server error has occurred.

Error Code: 0x8007007b

Notification: ExecuteRequestHandler

Module: IsapiModule

Requested URL: http://localhost:80/ReportServer

Physical Path: c:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer

When I enable Failed Request Tracing Rules and view the log output I am supposing that the actual problem is in the 2nd call where there are 2 backslashes before the actual filename in the specified path:


CALL_ISAPI_EXTENSION DllName="C:\Windows\Microsoft.NET\Framework\v2.0.50727\\aspnet_isapi.dll"


Handling 404 page not found with Error page



      How do i handle 404 page not found?

Inserting personal error message in ValidationSummary



I am creating a web form that requires a lot of validation. I use many of the validation control in asp.net already like RequiredFieldValidator and CompareValidator. 

My Problem: after my custom validation for the value entered return an error message, and I pressed enter key when the field is empty, my custom error message is overlapped by my ValidationSummary. 

Setting my custom error to visible = false on button click also does not seem to work as it requires for me to enter the value first.

This made me think, is there a way to insert my custom validation inside the ValidationSummary as an error message like for other validation control?

Thanks in advance

Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo

Type or namespace error.


A couple of days ago I started getting an unusual behavior when compiling Website projects. I have referenced class libraries added to my bin folder that are also correctely referenced in using statements in my aspx.cs code behind. When I compile, I get the 

Error 4 The type or namespace name 'CommonClassLibrary' could not be found (are you missing a using directive or an assembly reference?) C:\Dev\Fiscal_Portal\Implementation\FMS Portal Site_new\App_Code\BLL\DataTables.cs 1 7 C:\...\FMS Portal Site_new\

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

error message that would typically be received when the dll has not been added as a reference or added in a using statement.

I can eliminate the error by adding an


HTTP Error 403 - Forbidden


(VB Express website directed me to ASP.NET Web Services which in turn redirected me to this forum).

 Hopefully someone can help me here...... 

I am using VIsual Web Developer and downloaded the small business application to use as a starting point to help my wife get a website up for her small business. When I load the application, I can F5 and it runs fine but as soon as I make any modification to the app and hit F5, I get the HTTP Error 403 - Forbidden when it tries to show the website.

I notice a pop up that occurs when I run that allows me to choose the link for my app and it displays correctly (I close the webpage that has the error on it).

This seems like a pain, is there a setting I'm missing - I would think that this should "just work".

What's up?????



Webmatrix error


When i try to do anything in webmatrix it shuts down.   i get this error in the log

pplication: WebMatrix.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: Unrecoverable system error.
   at System.Environment.FailFast(System.String)
   at MS.Internal.Invariant.FailFast(System.String, System.String)

Insert Error not helpful



I am using VS2010

When I try to updated or insert a record in my User table I am getting an error that does not make sense to me and I cannot figure out what is wrong.

Also, when I try to insert a new record I get a validation error saying that the Id is required. However it is an identity field in the db so it should not be necessary to send it to the server.

Could you please shed some light?


An error has occurred.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.Web.UI.WebControls.EntityOperationException: An error has occurred.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace:

[EntityOperationException: An error has occurred.]
   Microsoft.Web.UI.WebControls.DomainDataSourceView.PerformCudOperation(ChangeSetEntry operation, Action`1 operationPerformingEvent, Action`1 operationPerformedEvent) +331
   Microsoft.Web.UI.WebControls.DomainDataSourceView.UpdateObject(Object oldEntity, O

Error when updating. Supposedly updating ID without being asked.



Server Error in '/' Application.

Value of member 'ID' of an object of type 'Ref' changed.
A member defining the identity of the object cannot be changed.
Consider adding a new object with new identity and deleting the existing one instead.

I get this error whenever I attempt to update an entry. Even an entry that has had nothing altered. I have tried to circumvent it but I think it must be a simple oversight. How could I have caused an ID update using the Edit.aspx page of dynamic data? Thank you in advance for the help!

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