SQL Server 2008 및 SQL Server 2005 및 날짜 시간 사용
2008 데이터베이스에 대해 엔티티 프레임 워크 모델을 작성했습니다. 모든 것은 2008 데이터베이스와 호환됩니다. 2005 데이터베이스에서 엔티티를 업데이트하려고하면이 오류가 발생합니다.
사용중인 SQL Server 버전이 'datetime2 데이터 형식을 지원하지 않습니다.
특히 데이터베이스를 만들 때 2008 기능을 사용하지 않았습니다. 코드에서 datetime2에 대한 참조를 찾을 수 없습니다. 그리고 예, 열은 데이터베이스에서 "datetime"으로 정의됩니다.
빠른 구글은 해결책 처럼 보이는 것을 알려줍니다 .
파일 편집기에서 EDMX를 엽니 다 (또는 Visual Studio에서“열기…”및 XML 편집기 선택). 상단에는 스토리지 모델이 있으며 ProviderManifestToken 속성이 있습니다. 이 값은 2008이어야합니다.이 값을 2005로 변경하고 다시 컴파일하면 모든 것이 작동합니다.
참고 : 데이터베이스에서 모델을 업데이트 할 때마다이 작업을 수행해야합니다.
라인의 빠른보기 :
<Schema Namespace="Foobar.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005" >
이것은 매우 실망스럽고 MS가 특정 SQL 버전을 대상으로 할 수 있도록하지 않기로 결정한 것에 놀랐습니다. 우리가 2005 년을 목표로 삼고 있는지 확인하기 위해 간단한 콘솔 앱을 작성하여 PreBuild 단계에서 호출했습니다.
사전 빌드 단계는 다음과 같습니다.
$(SolutionDir)Artifacts\SetEdmxVer\SetEdmxSqlVersion $(ProjectDir)MyModel.edmx 2005
코드는 다음과 같습니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace SetEdmxSqlVersion
{
class Program
{
static void Main(string[] args)
{
if (2 != args.Length)
{
Console.WriteLine("usage: SetEdmxSqlVersion <edmxFile> <sqlVer>");
return;
}
string edmxFilename = args[0];
string ver = args[1];
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(edmxFilename);
XmlNamespaceManager mgr = new XmlNamespaceManager(xmlDoc.NameTable);
mgr.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2008/10/edmx");
mgr.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/02/edm/ssdl");
XmlNode node = xmlDoc.DocumentElement.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema", mgr);
if (node == null)
{
Console.WriteLine("Could not find Schema node");
}
else
{
Console.WriteLine("Setting EDMX version to {0} in file {1}", ver, edmxFilename);
node.Attributes["ProviderManifestToken"].Value = ver;
xmlDoc.Save(edmxFilename);
}
}
}
}
위의 @Vance의 편리한 콘솔 앱을 사용하여 BeforeBuild 이벤트로 다음을 사용했습니다.
<Target Name="BeforeBuild">
<!--Check out BD.edmx, Another.edmx, all configs-->
<Exec Command="$(SolutionDir)\Library\tf checkout /lock:none $(ProjectDir)Generation\DB.edmx" />
<Exec Command="$(SolutionDir)\Library\tf checkout /lock:none $(ProjectDir)Generation\Another.edmx" />
<!--Set to 2008 for Dev-->
<Exec Condition=" '$(Configuration)' == 'DEV1' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\DB.edmx 2008" />
<Exec Condition=" '$(Configuration)' == 'DEV1' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\Another.edmx 2008" />
<Exec Condition=" '$(Configuration)' == 'DEV2' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\DB.edmx 2008" />
<Exec Condition=" '$(Configuration)' == 'DEV2' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\Another.edmx 2008" />
<!--Set to 2005 for Deployments-->
<Exec Condition=" '$(Configuration)' == 'TEST' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\DB.edmx 2005" />
<Exec Condition=" '$(Configuration)' == 'TEST' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\Another.edmx 2005" />
<Exec Condition=" '$(Configuration)' == 'PRODUCTION' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\DB.edmx 2005" />
<Exec Condition=" '$(Configuration)' == 'PRODUCTION' " Command="$(SolutionDir)Library\SetEdmxSqlVersion $(ProjectDir)Generation\Another.edmx 2005" />
</Target>
성가신 재배치를 피하기 때문에 매우 편리합니다. Vance를 공유해 주셔서 감사합니다.
I've added TF.exe to the Library solution folder and this helps, as I can now check out the edmx files before trying to edit them, as part of the build. Also I have added this with conditions, so that it sets to 2005 for deployments to the server and back to 2008 for the Dev machine sln configurations. Also to mention you need to add the actual SetEdmxSqlVersion.exe (and .pdb) file(s) to the Library folder (or wherever else you want to keep these bits).
Thanks very much @Vance. Really neat, massive time saver and keeps my builds totally automated and pain free :)
Had a similar problem with 2012 vs. 2008. It can be solved with a BeforeBuild event using XmlPeek and XmlPoke:
<Target Name="BeforeBuild">
<XmlPeek XmlInputPath="$(ProjectDir)MyModel.edmx"
Namespaces="<Namespace Prefix='edmx' Uri='http://schemas.microsoft.com/ado/2009/11/edmx'/><Namespace Prefix='ssdl' Uri='http://schemas.microsoft.com/ado/2009/11/edm/ssdl'/>"
Query="/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/@ProviderManifestToken">
<Output TaskParameter="Result" ItemName="TargetedSQLVersion" />
</XmlPeek>
<XmlPoke Condition="@(TargetedSQLVersion) != 2008"
XmlInputPath="$(ProjectDir)MyModel.edmx"
Namespaces="<Namespace Prefix='edmx' Uri='http://schemas.microsoft.com/ado/2009/11/edmx'/><Namespace Prefix='ssdl' Uri='http://schemas.microsoft.com/ado/2009/11/edm/ssdl'/>"
Query="/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/@ProviderManifestToken"
Value="2008">
</XmlPoke>
</Target>
If you dislike automated replacement, you can simply replace the XmlPoke task with an Error task.
For the benefit of people who encounter the same issue but are using Code First, check out my answer here about how to change the ProviderManifestToken
in Code First. It involves creating a DbModelBuilder
manually and passing a DbProviderInfo
instance (with the appropriate token) when calling the model builder's Build
method.
Better solution to me is instead of manually editing EDMX file is just open edmx in design mode and in context menu "Update Model from Database...". You have to be pointing to right SQL version of course whatever this is for you.
We had this error on SQL2005 v.3, where we did not have it on SQL2005 v.4.
Adding SQL2005 to the connection string fixed our specific problem.
We haven't identified why yet, and did not want to modify code to provide the token as solved above (issue manifested during deployment).
참고URL : https://stackoverflow.com/questions/316422/using-sql-server-2008-and-sql-server-2005-and-date-time
'Programming' 카테고리의 다른 글
명령 행을 사용하여 시작된 후 프로세스의 STDERR / STDOUT을 리디렉션 하시겠습니까? (0) | 2020.07.18 |
---|---|
Node.js 템플릿을위한 Jade와 EJS의 장단점은 무엇입니까? (0) | 2020.07.18 |
람다 식에는 코드 줄 저장 이외의 용도가 있습니까? (0) | 2020.07.18 |
플레이시 휴식! (0) | 2020.07.18 |
vb.net에서 중첩 / 종료 (0) | 2020.07.18 |