The model backing the ‘FilmContext’ context has changed since the database was created. Consider using Code First Migrations to update the database

This happened when the database connection string had not been setup in the App.config, so Code First went ahead and created a new database, which I then deleted and set up the connection string to my existing database. I then started getting this error.

Workaround by adding Entity.Database.SetInitializer in the context:

Protected Overrides Sub OnModelCreating(modelBuilder As System.Data.Entity.DbModelBuilder)
Entity.Database.SetInitializer(Of FilmContext)(Nothing) ‘To not initialise the database
modelBuilder.Configurations.Add(New FilmsMap)
End Sub

Entity Framework connection error: System.Data.ProviderIncompatibleException

For me this occurred when I used Entity Framework Power Tools Beta 3, and then used the “Entity Framework > View Entity Data Model (Read-Only)” functionality. The error was:

System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct. —> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. —> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

This was because the Project containing the context was a class library and was not the startup project. I changed the App.config in the class library but this had no effect. To resolve you change the App.config file in the project marked as the startup project.

Might also be that a reference to the project containing the context is missing.

Solved.

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)

SQL Linked Server and SQL Server Agent

When using SQL Server Agent to do a job that has a view or other that connects to a remote server then you may get the following issues:

Error “Linked servers cannot be used under impersonation without a mapping for the impersonated login”

Solution 1:

  1. Create a login on the end server as:
    USE [master]
    GO
    CREATE LOGIN [NT SERVICE\SQLSERVERAGENT] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[British]
    GO
  2. Then give this login the permissions on the objects required.
  3. Back on the host right-click on the remote server > Properties > Security >
  4. Add “Local server login to remote server login mappings:”
    Add “NT SERVICE\SQLSERVERAGENT” Impersonate = ticked on – No remote user or password
    Suggest use “Be made using the login’s current security context”

Solution 2:

  1. Create a new SQL server login on the end server and give it the required permissions
  2. Back on the host right-click on the remote server > Properties > Security >
  3. Add “Local server login to remote server login mappings:”
    Add “NT SERVICE\SQLSERVERAGENT” Impersonate = ticked off – Remote user = your new user, Password = new password
    Suggest use “Be made using the login’s current security context”

 

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

ASP.Net publish troubleshooting

Was trying to publish to Azure Websites, but it was hanging on “Publish Started”

The Start-up project was another project, so switched it to the website and then published ok. Deliberately switched it back to see if the problem was this and the error returned.

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.