Share Coding

Tutorials, Problems, Stuffs …

SQL Server Linked Servers and Create View

Server Objects > New > Linked Server…

1

Input server name (or IP):

2

Security > Without using security context or input the remote login name and password:

3

If the view is created from “right-click > New Views”, an error received when:

Select * from [10.8.8.212].[DBName].[dbo].[TableName]
Error in FROM clause: near '10.8'. 
Unable to parse query text.

The bracket [] will be auto removed by MS Management studio:

4

You may create the view successfully by using SQL:

CREATE VIEW [dbo].[DB_VIEW]
AS
SELECT *
FROM [10.8.8.212].[DBName].[dbo].[TableName]
GO

Error “Copying file obj\Debug\build.force…” and Warning “Source file ‘obj\Debug\\TemporaryGeneratedFile…” in VS2013

Error 5 Copying file obj\Debug\build.force to obj\Debug\Package\PackageTmp\obj\Debug\build.force failed. Could not find file 'obj\Debug\build.force'.
Warning	3 Source file 'obj\Debug\\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs' specified multiple times	
Warning	4 Source file 'obj\Debug\\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs' specified multiple times	
Warning	2 Source file 'obj\Debug\\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs' specified multiple times

I encountered above messages in VS2013. I tried to clean solution, rebuild project and also run VS as administrator, but those doesn’t work for me.

My solution is open xxxxxx.csproj with a notepad and delete the lines from csproj file:

<Content Include="obj\Debug\build.force" />
<Compile Include="obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs" />
<Compile Include="obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs" />
<Compile Include="obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs" />

Entity Framework Update table without primary Key (II)

The property ‘xxx’ is part of the object’s key information and cannot be modified

UserRight dboUserRight = DBModel.UserRights.FirstOrDefault(x => x.UserID == id 
                                                             && x.PageID == pid); 
dboUserRight.CanWrite = newValue; 
DBModel.SaveChanges();

Method 1: Replace old record

UserRight updatedUserRight = new UserRight();
updatedUserRight.CanWrite = newValue;
updatedUserRight.OtherProperty = xxxx;
DBModel.UserRights.Add(updatedUserRight);
DBModel.UserRights.Remove(dboUserRight);
DBModel.SaveChanges();

Entity Framework Update table without primary Key

Exception throw when try to call DBModel.SaveChanges()

System.Data.Entity.Infrastructure.DbUpdateException: Unable to update the EntitySet ‘role_app_right’ because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. —> System.Data.Entity.Core.UpdateException: Unable to update the EntitySet ‘role_app_right’ because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

  1. Right click on the edmx file, select Open with… > XML Text editor
  2. Find the EntitySet in edmx:StorageModels > EntityContainer
  3. Remove the DefiningQuery entirely
  4. Rename [store:Schema=”dbo”] to [Schema=”dbo”]

123

<EntitySet Name=“role_app_right” EntityType=“Self.role_app_right” store:Type=“Tables” Schema=“dbo” />

 

IIS 8.0+ Shown Custom Error Message

<system.webServer>
    <httpErrors existingResponse="PassThrough"/>
</system.webServer>
1 2