不能得到的SQL Server Compact 3.5 / 4 ASP .NET MVC 2的工作 [英] Can't get sql server compact 3.5 / 4 to work with ASP .NET MVC 2

查看:230
本文介绍了不能得到的SQL Server Compact 3.5 / 4 ASP .NET MVC 2的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Visual Studio 2008专业版。

I'm using Visual Studio 2008 Pro.

我可能失去了一些东西很明显这里,但我一直在试图获得对CTP的SQL Server Compact 4在我的asp.net MVC应用程序的工作。我能找到下一个关于如何设置此没有任何指令或工作的示例应用程序。我的目标是私人安装这样我就可以只包括它在我的web应用程序,而无需做我的域名托管SQL Server安装程序。这其实只是我闲聊,并试图弄清楚这一点。我不打算举办一个市场或任何与此有关。

I'm probably missing something very obvious here, but I've been trying to get the CTP for Sql Server compact 4 to work in my asp.net mvc application. I can find next to no instruction on how to set this up or a working example application. My goal is a private install so I can just include it in my web app without having to do sql server setup on my domain hosting. This is really just me shooting the breeze and trying to figure this out. I don't plan to host a market or anything with this.

所以,我复制了所有在基地4.0方向安装dll的(C:\\ Program Files文件\\ SQL Server精简\\ V4.0)在我的应用程序中的lib文件夹。我设置的副本输出方向选项设置为复制如果较新的。然后,我引用对System.Data.SqlServerCe DLL并设置'复制本地设置为True。

So, I've copied all the dll's that install in the base 4.0 direction (c:\Program Files\Sql Server compact\v4.0) to a lib folder in my application. I've set the copy to output direction option to 'Copy if Newer'. I then reference the System.Data.SqlServerCE dll and set 'Copy Local' to True.

我创建通过SQL工作室前preSS SDF文件。一个重要的注意的是,我没有看到一个选项用于创建CE 4.0版本的文件,所以它使用CE 3.5创建的。我创建了一些表,增加了几行的表,* .sdf文件复制到我的App_Data目录。值得一提的是,从VS 2008中,这个文件从来没有出现在我的项目,但它确实在App_Data目录的物理位置存在。我不知道这是为什么。

I created an sdf file via Sql Studio Express. An important note is that I did not see an option for creating a CE 4.0 version of this file, so it was created using CE 3.5. I create a few tables, add a few rows to those tables, copy the *.sdf file to my App_Data directory. It's worth mentioning that, from inside VS 2008, this file never appears in my project, but it does exist in the physical location of the App_Data directory. I'm not sure why this is.

接下来,我只是尝试使通过我的SDF文件的基本连接:

Next, I just try making a basic connection to my sdf file via:

SqlCeConnection conn = new SqlCeConnection("DataSource=rpg.sdf");

这会产生以下错误:

Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8402. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

我从这里的身影,我只是尝试让SQL CE 3.5的工作。升级我的SQL CE 3.5的本地安装到SP2。我复制的dll在该基地的位置(C:\\ Program Files文件\\ SQL Server精简\\ v3.5版本),包括删除,并从我的项目引用readding对System.Data.SqlServerCe DLL的版本。

I figure from here, I'd just try getting Sql CE 3.5 to work. I upgrade my local installation of Sql CE 3.5 to sp2. I copy the dlls at the base location (c:\Program Files\Sql Server compact\v3.5), including removing and readding the version of the System.Data.SqlServerCE dll from my project references.

在这里奇怪的是,当我点击右键,看引用SqlServerCE DLL的属性,它总是说,这是4.0.0.1版本。

The curious thing here is when I right click and look at the properties of the referenced SqlServerCE dll, it always says it's version 4.0.0.1.

大家好,我真的可以在这里使用了一些方向。我已搜查堆栈溢出,帮助文档,书籍在线和Google搜索。我真的没有发现任何东西,这需要从最高层对于任何CE 3.5或4.0,并告诉我到底是什么DLL的添加,在那里把他们来说,如何引用它们,如何将.sdf文件添加到我的项目,连接到它,并从中查询。我也遇到了一些提到,应该使用SQL CE 3.5的门户网站的IBuySpy示例应用程序,但实际上并不能导航MSDN下载迷宫得到它。理想情况下,我想设置为CE 4.0的私人部署。

Guys, I really could use some direction here. I have searched stack overflow, the help docs, books online, and googled. I really haven't found anything that takes this from the very top for either CE 3.5 or 4.0 and tells me exactly what dll's to add, where to put them, how to reference them, how to add the .sdf file to my project, connect to it, and query from it. I did come across a few mentions of an IBuySpy portal sample app that was supposed to use Sql CE 3.5, but can't actually navigate the msdn download maze to get to it. Ideally, I want to setup a private deploy for CE 4.0.

我洗耳恭听。建议,分,无论是高度AP preciated。谢谢!

I'm all ears. Suggestions, points, whatever would be highly appreciated. Thank you!

是我没有看到的KB。它并没有帮助

请参阅在这里: http://support.microsoft.com/kb/974247

结果从CORFLAG

好吧,试过了,这些都是我的结果:
    C:\\开发\\ Mvc2MessingAround \\ Mvc2MessingAround \\ BIN \\库> corflags System.Data这。
    SqlServerCe.dll
    微软(R).NET框架CorFlags转换工具。版本3.5.21022.8
    版权所有(c)Microsoft公司。保留所有权利。

Okay, tried that and these are my results: C:\Development\Mvc2MessingAround\Mvc2MessingAround\bin\Lib>corflags System.Data. SqlServerCe.dll Microsoft (R) .NET Framework CorFlags Conversion Tool. Version 3.5.21022.8 Copyright (c) Microsoft Corporation. All rights reserved.

Version   : v2.0.50727
CLR Header: 2.5
PE        : PE32
CorFlags  : 9
ILONLY    : 1
32BIT     : 0
Signed    : 1

我就发誓我安装了SQL CE(3.5 / 4)两个版本的x86版本。安装程序可能会得到某种方式迷惑,因为我的处理器是64位的能力,但我运行Windows XP SP 3 32位。结果似乎表明它是64位。是这样吗?

I would have sworn I installed the x86 version of both versions of Sql CE (3.5/4). The installer might have gotten confused somehow because my processor is 64bit capable, but i'm running Windows xp sp 3 32 bit. The results seem to indicate it's 64 bit. Is that the case?

ADDED详情

要日期下面的配置已经尝试了2台机器。两者都是了Windows XP SP3具有64位计算能力的处理器32位。两个开发环境是VS 2008专业版。机2来了之后一个新的结果安装SQL CE 4的CTP。

To date the configurations below have been tried on 2 machines. Both are Windows xp sp3 32 bit with a 64 bit capable processor. The development environment on both is VS 2008 Pro. The results on machine 2 come after a fresh install of the Sql CE 4 Ctp.

配置#1

myapp\bin\
     System.Data.SqlServerCe.dll

myapp\bin\private
    amd64
    x86

myapp\bin\private\x86
    sqlceca40.dll
    sqlcecompact40.dll
    sqlceer40EN.dll
    sqlceme40.dll
    sqlceqp40.dll
    sqlcese40.dll

myapp\bin\private\amd64
    sqlceca40.dll
    sqlcecompact40.dll
    sqlceer40EN.dll
    sqlceme40.dll
    sqlceqp40.dll
    sqlcese40.dll

错误:

An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.DLL but was not handled in user code

Additional information: Unable to load the native components of SQL Server Compact corresponding to the ADO.NET provider of version 8402. Install the correct version of SQL Server Compact. Refer to KB article 974247 for more details.

code:

SqlCeConnection conn = new SqlCeConnection();

配置2

同#1,但在System.Data.SqlServerCE.Entity.dll的myapp \\ bin中的方向。

Same as #1, but with System.Data.SqlServerCE.Entity.dll at myapp\bin direction.

触及上方的code之前的页面错误。这是消息:

The page errors before hitting the code above. This is the message:

无法加载文件或程序集System.Data.SqlServerCe.Entity或它的一个依赖。这个组件由一运行时间比当前加载运行时更新构建并不能装载。

Could not load file or assembly 'System.Data.SqlServerCe.Entity' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

说明:在当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

异常详细信息:System.BadImageFormatException:未能加载文件或程序集System.Data.SqlServerCe.Entity或它的一个依赖。这个组件由一运行时间比当前加载运行时更新构建并不能装载。

Exception Details: System.BadImageFormatException: Could not load file or assembly 'System.Data.SqlServerCe.Entity' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

我在2008年临VS检查项目设置和.Net 3.5框架设置为目标。

I've checked the project settings in VS 2008 Pro and the .Net 3.5 framework is set as the target.

配置3

同#1,除了System.Data.SqlServerCE.dll从MyApp的\\ BIN \\私人文件夹中引用。

Same as #1, except the System.Data.SqlServerCE.dll is referenced from the myapp\bin\private folder.

结果是相同的配置#1(错误消息是100%相同,并在同一行上code的误差occurrs)

Results are the same as CONFIGURATION #1 (error message is 100% same and the error occurrs on the same line of code).

正确的配置

每Erik的指令(有我更仔细地跟在他们后面),安装应

Per Erik's instructions (had I followed them more carefully), the setup should be

myapp\bin
    x86
    amd64
    System.Data.SqlServerCE.dll

直接从为code中的bin文件夹参考的System.Data.SqlServerCE.dll。我愚蠢的想法需要纳入私人文件夹,但事实并非如此。除非您使用的是.NET 4.0解决方案,不要把System.Data.SqlServerCE.Entity.dll bin文件夹。我不认为DLL工程瓦特/ 3.5。

Reference the System.Data.SqlServerCE.dll directly from the bin folder for the code. My folly was thinking the Private folder needed to be included, but it doesn't. Do not put the System.Data.SqlServerCE.Entity.dll in the bin folder unless you are using a .net 4.0 solution. I don't think that dll works w/ 3.5.

有用的链接:

<一个href=\"http://blogs.msdn.com/b/sqlservercompact/archive/2010/07/07/introducing-sql-server-compact-4-0-the-next-gen-embedded-database-from-microsoft.aspx\">http://blogs.msdn.com/b/sqlservercompact/archive/2010/07/07/introducing-sql-server-compact-4-0-the-next-gen-embedded-database-from-microsoft.aspx

推荐答案

SQL CE 3.5不使用ASP.NET,您必须使用4.0 CTP。

SQL CE 3.5 does not work with ASP.NET, you must use 4.0 CTP.

从这里 下载。

Download from here.

安装运行。

复制下面的目录内容(包括x86和AMD64文件夹)到你的ASP.NET应用程序的bin文件夹:
C:\\ Program Files文件\\ Microsoft SQL Server的精简版\\ V4.0 \\私人

Copy the following directory contents (including the x86 and amd64 folders) to the bin folder of your ASP.NET app: C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Private

更新:使用System.Data.SqlServerCe.dll从桌面文件夹,以避免中等信任问题

myapp\bin\ 
 System.Data.SqlServerCe.dll 

myapp\bin\x86 
 sqlceca40.dll 
 sqlcecompact40.dll 
 sqlceer40EN.dll 
 sqlceme40.dll 
 sqlceqp40.dll 
 sqlcese40.dll 

myapp\bin\amd64 
 sqlceca40.dll 
 sqlcecompact40.dll 
 sqlceer40EN.dll 
 sqlceme40.dll 
 sqlceqp40.dll 
 sqlcese40.dll 

添加一个引用到你只要把你的/ bin文件夹中System.Data.SqlServerCe.dll文件。

Add a reference to the System.Data.SqlServerCe.dll file you just put in your /bin folder.

将SQL精简SDF文件在App_Data文件夹中。

Place the SQL Compact sdf file in your App_Data folder.

添加连接字符串:

<connectionStrings>
   <add name ="NorthWind"
   connectionString="data source=|DataDirectory|\Nw40.sdf" />
</connectionStrings>

连接! : - )

Connect! :-)

using System.Data.SqlServerCe;

    protected void Page_Load(object sender, EventArgs e)
    {
        using (SqlCeConnection conn = new SqlCeConnection())
        {
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
            conn.Open();
            using (SqlCeCommand cmd = new SqlCeCommand("SELECT TOP (1) [Category Name] FROM Categories", conn))
            {
                string valueFromDb = (string)cmd.ExecuteScalar();
                Response.Write(string.Format("{0} Time {1}", valueFromDb, DateTime.Now.ToLongTimeString()));
            }
        }
    }

这篇关于不能得到的SQL Server Compact 3.5 / 4 ASP .NET MVC 2的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆