0
votes

I am getting the error 'Cannot execute as the database principal because the principal "kc" does not exist...' when I try to execute a Microsoft web application locally that connects to a SQL Server database. It application works fine when it is connecting to a remote server.

I copied the database on the remote server to my local computer to make changes. This is the connection string when connecting to the remote server:

<add name="Database" connectionString="Server=KC-DEV2;Database=ICKC;User Id=kc;Password=kc" providerName="System.Data.SqlClient" />

The owner of the database is 'KC\Administrator'. I use SQL Server Authentication.

The connection string when I am connected to the database locally is as follows:

 <add name="Database" connectionString="Server=localhost;Database=ICKC;Trusted_Connection=Yes;" providerName="System.Data.SqlClient" />

I restored the remote database to my local computer. The owner of the ICKC database is KC\GSantin. I connect to the database using Windows Authentication.

From what I found on the web, this error can often be from no owner on the database but that is not the case for me. There is a login for 'kc' in the local database. It is a backup and restore of the remoste one so everything is the same.

Does anybody have any suggestions how I can fix this problem?

Thanks, Gloria

1

1 Answers

0
votes

kc should be a SQL Login based on your remote server. Once you restore the database from remote server to local, the SQL user came along. You must have created kc SQL login manually. What is going to miss here would be mapping between them. can you run sp_change_users_logins 'Report' and check if there is any orphan users. mostly you should see kc. If yes then run sp_change_users_logins 'update_one','kc','kc' Else You need to capture profiler trace to find exact point of failure.