Daily using/supporting

Get Firefox browser!
Get Thunderbird!
Get Opera browser!
Get The Gimp!
Get Inkscape!
Get LibreOffice!
Get Videolan!
Get Linux!
Get Mandriva!
Get Joomla!
Hacker Emblem

Archives

Which topics would you like us to cover more?

Latest comments

Home
Adding data to the database with Visual Studio Data Generation Plan
Architecture, security and coding
Written by Division by Zero   
Wednesday, 22 February 2012 12:00

An hour ago I needed to use the Data Generation Plan to add generated data to my database. After setting up the generation plan I executed it. I got the following error:

"violation of primary key constraint 'PK_ '.Cannot insert duplicate key in object 'Pk_...'"

Apparently Visual Studio tries to insert the ID's and starts counting with 1. This will work fine on an empty database, but not in this case. I searched a while to find a solution, but couldn't find any. This is what I did to solve the problem (it is a little bit of hacking, but it works):

At first I opened the .dgen file (there is a directory named "Data Generation Plans" in your database solution) with notepad++. The id's look something like this:

<Element Type="ISql100SimpleColumn" Name="[dbo].[Authentication].[ID]">
    <Property Name="IsNullable" Value="False" />
    <Property Name="IsIdentity" Value="True" />
    <Relationship Name="TypeSpecifier">
        <Entry>
            <Element Type="ISql90TypeSpecifier">
                <Relationship Name="Type">
                    <Entry>
                        <References ExternalSource="BuiltIns" Name="[int]" />
                    </Entry>
                </Relationship>
            </Element>
        </Entry>
    </Relationship>
    <Annotation Type="ColumnConfigAnnotation">
        <Property Name="Selected" Value="True" />
        <Property Name="Seed" Value="5" />
    </Annotation>
</Element>

My first try was to set the IsIdentity property to false. Visual studio still handles the field as a readonly field. So this isn't a solution.

The second try was to remove the IsIdentity property. After saving Visual Studio asked me to update the plan. After the update Visual Studio asked me to update the plan with the latest database properties. Here you will have to decline. If you do this, your changes will be undone.

After this you will be able to set the minimal value for the id-column. Fill in the highest available id from you database +1 and you're almost good to go!

SQL Server will not accept identity insert by default. You must enable this before you run the plan. Another way to do this is to temporarily alter the tables you want to use and disable the Identity Seed. If you run the Generation Plan now, it will run ok.

Of course be very cautious. You are disabling 'safety controls' and you will be able to mess up your database.

 
Best of 2011
Blog / Personal
Written by Division by Zero   
Saturday, 31 December 2011 10:12

The end of 2011 is nearly there. It's time to look back on a year of blogging. Here are some top 5's from 2011.

The 5 most popular posts:

  1. How to reset you Kindle 3, even if the slide doesn't work
  2. Creating a HL7 Ack/Nack message in .Net using nHapi
  3. How to create an application supporting multiple HL7 version using nHapi
  4. nHapi example
  5. Inside the Kindle 3 (Latest Generation)

 

The 5 most interesting comments/discussions:

  1. Is Atheism purely rational?
  2. Emotions of a developer during a project
  3. Why nHapi sometimes parses a message as a generic message
  4. Creating a HL7 Ack/Nack message in .Net using nHapi
  5. How to reset you Kindle 3, even if the slide doesn't work

 

My 5 personal favourite posts (This is a hard one!):

  1. Emotions of a developer during a project
  2. The psychology of rites of passage
  3. Making a threatmodel, part 1: Business usecases
  4. How to reset you Kindle 3, even if the slide doesn't work
  5. Green architecture: Sustainability and IT architecture

 

Happy 2012!

 
Friday - link-day #78 - Colors, Mythical, Girls, Smurf and Pictures
Blog / Personal
Written by Division by Zero   
Friday, 30 December 2011 10:00

Here are the links for the last Friday of 2011!

 
Almost Christmas: consumerism
Theology
Written by Division by Zero   
Saturday, 24 December 2011 09:28

It's almost Christmas... but what does Christmas mean to you? Here is a video for some contemplation.

 
Friday - link-day #77 - Searching, Microsoft, Music, Hacking and Volcanoes
Blog / Personal
Written by Division by Zero   
Friday, 23 December 2011 10:00

Getting closer to Christmas!

 
<< Start < prev 1 2 3 4 5 6 7 8 9 10 next > End >>

Page 1 of 69

If the human brain was simple enough for us to understand we'd be so simple we couldn't understand. - Unknown


© 2009 - 2012, Division by Zero

Template based on the empire template by joomlashack 

Valid XHTML 1.0 Strict  Valid CSS!  Creative Commons License
This work by Division by Zero is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.