Entity Framework Error “The property ‘id’ is part of the object’s key information and cannot be modified”

If you load an entity then change its key you may get this message.

If you really must change the key, for instance on an entity which does not use identity, then you may set the entity’s state to Added then change the key, then change the state to Unchanged.

To change state you could use

    Sub SetEntityState(myObject As Object, myState As System.Data.Entity.EntityState)
        context.Entry(myObject).State = myState
    End Sub

— Original 8-Jul-2013 —

In my case this was because I was using context.Products.Find(123) and then manipulating the item, perhaps adding it again. So the Find method will cache it the first time. So if you want to do a subsequent Add/Modify then perhaps best to clear that store. You can do this with.

For each p as product in context.products
   context.enty(p).state = detached
next

It was not that the key was wrong.

 

Error setting up SQL Server CDC – Change Data Capture

Error when using:
EXECUTE sys.sp_cdc_enable_db

Msg 22830, Level 16, State 1, Procedure sp_cdc_enable_db_internal, Line 193
Could not update the metadata that indicates database <dbname> is enabled for Change Data Capture. The failure occurred when executing the command ‘SetCDCTracked(Value = 1)’. The error returned was 15517: ‘Cannot execute as the database principal because the principal “dbo” does not exist, this type of principal cannot be impersonated, or you do not have permission.’. Use the action and error to determine the cause of the failure and resubmit the request.

Solution:

Database > Properties > Files >
Check that the databse has an owner

For me this went wrong because ‘dbo’ existed on the server (pc) where this database was created, but did not exist on this server (pc) (SQL Server Developer Edition)

Failed to connect to a windows service – Group Policy Client

Error on start-up of windows:

“Failed to connect to a windows service
Windows could not connect to the Group Policy Client service. This problem prevents standard users from logging on to the system.
As an administrative user, you can review the System Event Log for details about why the service didn’t respond”

Group Policy on login 2013-01-10

This also does not start a service:

Group Policy Service Not started 2013-06-12

 

Resolved with thanks to SQL-ER:

http://social.technet.microsoft.com/Forums/en-US/winserverGP/thread/ab15d601-0e38-4f9d-ab7f-5ad5ceda2a43

http://www.youtube.com/watch?v=4m5KEmckWK4&feature=youtu.be

 

“The crash of your computer during Windows Updates may have caused that !

I had this issue on my laptop since November, and it really bugged me.  I sifted through the event log and found the pattern of events that preceded the issue, and, probably, caused it.
In short, the pattern is as follows: Windows updates run automatically as scheduled, and when reboot is initiated after the updates are finished, the computer crashes (probably during reboot sequence).  When it boots up, it reports that the last shutdown was unexpected, and the issue begins to occur.
I spent 2 days trying to dig out a solution from the Internet, to no avail, until I came across this page.  It doesn’t say anything about this particular problem, but it gives more information about SVCHOST process that starts many services, including Group Policy Client.  It looks like during reboot a vital registry settings were lost during crash and Group Policy Client “don’t know” how to start.  Let me explain:
There are two places to look in the registry:

  1. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services this path should contain gpsvc key (a folder), which is responsible for service parameters and configuration.  I found that the key was intact, so, you do not touch anything here – just check that the key exists.
  2. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SVCHOST This is the most important path you should look into, as it must contain the keys and values referred in the key #1.  Below are descriptions what must be present there.
  • There must be Multi-String value called GPSvcGroup. My laptop was missing it.  So, you should create multi-string value named GPSvcGroup and assign it value GPSvc.
  • Next, you must create a key (a folder) and name it GPSvcGroup – this key normally should be there, but, again, it was missin on my laptop.
  • Then open newly-created GPSvcGroup folder and create 2 DWORD values:
  1. First called AuthenticationCapabilities and you must give it a value of 0x00003020 (or 12320 in decimal)
  2. Second is called CoInitializeSecurityParam and it must have value of 1.

Once you complete all steps above, reboot the computer and the problem will be fixed.

Video walkthrough for those who are not very technical is here: http://youtu.be/4m5KEmckWK4

I am so relieved I was able to fix it, and hope this will help others with the similar issue.”

 

 

 

 

 

 

 

 

 

 

 

 

Restart results in reseed of identity by +1000

http://connect.microsoft.com/SQLServer/feedback/details/739013/failover-or-restart-results-in-reseed-of-identity

Copied from

http://i.ll.do/2013/01/how-to-solve-sql-server-2012-identity.htm

How to – Solve SQL Server 2012 Identity Problem. Identity increased by 1000 or 10000

Are you experiencing an identity problem with your SQL Server 2012? Do the identity seeds of your records get increased by 1000 or 10000(in my case it was 10000)? Do you wonder why this is happening and how you can solve this? Then keep reading…

Seems like Microsoft has changed the way they deal with identity values in SQL Server 2012 and as a result of this you can see identity gaps between your records after rebooting your SQL server instance or your server machine. There might be some other reasons for this id gaps, but in my case it was an automatic server restart after installing an update.
There are several ways to overcome this issue but here I will explain how I did it, which seemed to be the best way of overcoming this problem.
Below is a quote from a Microsoft post replying to this id crisis issue on “connect”:
If you require the same identity generation semantics as previous versions of SQL Server there are two options available:
•         Use trace flag 272
o This will cause a log record to be generated for each generated identity value. The performance of identity generation may be impacted by turning on this trace flag.
•         Use a sequence generator with the NO CACHE setting(http://msdn.microsoft.com/en-us/library/ff878091.aspx)
o This will cause a log record to be generated for each generated sequence value. Note that the performance of sequence value generation may be impacted by using NO CACHE.
What I did: Setting Trace Flag 272 on SQL Server 2012
  1. Open “SQL Server Configuration Manager”
  2. Click “SQL Server Services” on the left pane
  3. Right-click on your SQL Server instance name on the right pane ->Default: SQL Server(MSSQLSERVER)
  4. Click “Properties”
  5. Click “Startup Parameters”
  6. On the “specify a startup parameter” textbox type “-T272”
  7. Click “Add”
  8. Confirm the changes
Now you should be free of this annoying identity gap problem.

Hope this helps someone.
Good luck, Serdar.

l

SSRS Login failed for unattended execution account

SOLVED

> Start > All Programs > Reporting Services Configuration Manager

> Connect

> Execution Account

> Put in new Account + Password

WinForms Designer fails – warning …My.Resources.Resources has no property named … image

SOLUTION from Dave Anson C comment

http://connect.microsoft.com/VisualStudio/feedback/details/540265/designer-fails-warning-my-resources-resources-has-no-property-named

In the project References folder ensure there isn’t a reference to itself. (E.g. You have a project named WindowsApplication1. In the References folder you have a reference to WindowsApplication1)

This worked for me.

T-SQL unable to CAST text to a number – Byte order mark – Dodgy character at start

Scenario

Imported some data from Excel in form “156 x 54 x 16mm”. Parsed the text to get the 156. However this would not convert to a numeric.

Error converting data type nvarchar to numeric

After some exploration I discovered that the cursor required to steps through before the number. So a character was there that SQL Server could not display. To find this I used:

SELECT Code, UNICODE(LEFT(DimensionsTextImport, 1)) AS UnicodeTest FROM Product.<tablename>

And discovered text which would not convert had Unicode 65279

Solution

Create a new column and fill this with the data from the first column after a CASE statement.

UPDATE Product.Dimensions
SET DimensionsText = CASE
WHEN UNICODE(LEFT(DimensionsTextImport, 1)) = 65279 THEN SUBSTRING(DimensionsTextImport, 2, 50)
ELSE DimensionsTextImport END

With reference to:

http://stackoverflow.com/questions/6441208/unable-to-replace-char63-by-sql-query

http://www.fileformat.info/info/unicode/char/feff/index.htm

http://en.wikipedia.org/wiki/Byte_Order_Mark

 

 

Cannot use adobe reader to view pdf in your browser. Reader will now exit. Please exit your browser and try again.

PROBLEM:

  • Windows 7 64-bit
  • Internet Explorer 9
  • Adobe Reader 8.3.1

When opening a pdf in i.e

“Cannot use adobe reader to view pdf in your browser. Reader will now exit. Please exit your browser and try again.”

With reference to:

http://forums.adobe.com/thread/511010

Uninstall version 8.3.1 and install latest. For me this was 11.x.x

Crystal Reports Error: The request could not be submitted for background processing

If there is a database picture this may need to be re-imported

Outlook Expand Group fails. Cannot perform the requested operation.

Problem

Outlook Expand Group fails. Cannot perform the requested operation. The command selected is not valid for this recipient. The Operation failed.

Solution

Outlook > Contacts > Open Group > Update Now

One or more members of this contact group cannot be found…