2013-06-19 144 views
0

我想從我的C#的WinForm程序中打開.sdf文件(SQL Server精簡),我得到這個錯誤:打開SQL Server CE版本3.5和4

{Incompatible Database Version. If this was a compatible file, run repair. For other cases refer to documentation. [ Db version = 4000000,Requested version = 3505053,File name = \?\C:\inetpub\wwwroot\WS\bin\PC.sdf ]}

我需要有打開的可能性版本4和3.5

如何做到這一點?

感謝

回答

0

您必須部署到應用程序目錄中的SQL Server CE的兩個版本:http://robindotnet.wordpress.com/2010/02/28/how-to-deploy-the-sqlserver-compact-edition-software-locally/

你需要使用這樣的代碼來重新加載用於SQL Server CE 3.5和4.0裝配參考:

Assembly assembly = Assembly.LoadFrom("sqlcecompact35.dll"); 
Type type = assembly.GetType("SomeType"); 
object instanceOfSomeType = Activator.CreateInstance(type); 

糾正我,如果我錯了,但我相信,如果你在4.0版本中打開一個3.5版本的數據庫,它將升級,你將無法使用該版本打開它再次3.5提供商。這只是從個人經驗。

+0

如果您使用4.0提供程序打開3.5數據庫,您將收到錯誤消息。 – ErikEJ

+0

感謝您的澄清。在一個應用程序中重新加載提供程序是否是最佳實踐? –