如何将带有EF4的SQL CE 4.0部署到ASP.NET MVC 2.0的共享托管提供程序?
我已经在我的bin文件夹中包含了System.Data.SqlServerCe.dll和amd64 + x86目录,但仍然没有找到".net提供程序".我意识到它目前在CTP中,但这仅用于测试目的.我的项目+主机配置为.net 4.0
deployment asp.net-mvc sql-server-ce entity-framework-4 asp.net-mvc-2
自答问题以备将来参考:
如果您有一个删除并重新添加内容的表,则在插入ID等于现有ID的新行时可能会出现此错误:
Server Error in '/' Application.
A duplicate value cannot be inserted into a unique index. [ Table name = Stories,Constraint name = PK__Stories__000000000000001C ]
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.
Exception Details: System.Data.SqlServerCe.SqlCeException: A duplicate value cannot be inserted into a unique index. [ Table name = Stories,Constraint name = PK__Stories__000000000000001C ]
Source …Run Code Online (Sandbox Code Playgroud) asp.net exception-handling sql-server-ce sql-server-ce-4 asp.net-mvc-3
我已经创建了一个WCF REST服务,它使用nhibernate连接到sql server compact edition数据库.因此,我配置NHibernate数据源,如:
<property name="connection.connection_string">Data Source=[Path]\MyDb.sdf</property>
Run Code Online (Sandbox Code Playgroud)
我现在遇到的烦恼是我无法弄清楚如何避免在配置中写出绝对路径.这很烦人,因为我将数据库文件保存为App_Data文件夹中项目的一部分.所以我不应该更新路径,例如当我将项目部署到另一个位置时,即使绝对路径不同.
使用procmon我注意到如果我不在数据源配置中写一个绝对pat,它被解释为相对于路径:*C:\ Program Files(x86)\ Common Files\Microsoft Shared\DevServer\10.0*.
是否有可能让nhibernate假设我们想要将路径与应用程序bin文件夹相关联(这是我的App_Data/MyDb.sdf结束的地方)?
我有一个使用LINQ-to-SQL和SQL Server CE 4的应用程序.我知道这不是官方支持的,但我们已经使它工作,但有以下例外.有时,在尝试更新数据库时,我们会在数据库中出现一行错误.
我们使用a DataContext从数据库中选择一行,更新几列(一个布尔和一个字节列),然后我们调用SubmitChanges().当我们提交更改时,我们会收到包含以下堆栈跟踪的DivideByZeroException:
System.DivideByZeroException:尝试除以零.
在System.Data.SqlServerCe.NativeMethodsHelper.CompileQueryPlan(IntPtr的pQpCommand,字符串pwszCommandText,ResultSetOptions选项,IntPtr的[] pParamNames,IntPtr的prgBinding,的Int32 cDbBinding,IntPtr的&pQpPlan,IntPtr的PERROR)
在System.Data.SqlServerCe.NativeMethods.CompileQueryPlan(IntPtr的pQpCommand , System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior,
System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan())
中的字符串pwszCommandText,ResultSetOptions选项,IntPtr [] pParamNames,IntPtr prgBinding,Int32 cDbBinding,IntPtr&pQpPlan,IntPtr pError)串的方法,ResultSetOptions选项)
在System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery()
在System.Data.Linq.SqlClient.SqlProvider.Execute(表达式查询,queryInfo queryInfo,IObjectReaderFactory工厂,对象[] parentArgs,对象[] userArgs, System.Data.Linq.SqlClient.SqlProvider.ExecuteAll中的ICompiledSubQuery [] subQueries,Object lastResult)
(表达式查询,QueryInfo [] queryInfos,IObjectReaderF actory工厂,对象[] userArguments,ICompiledSubQuery []子查询)
在System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询)
在System.Data.Linq.ChangeDirector.StandardChangeDirector. DynamicUpdate(TrackedObject项目)
在System.Data.Linq.ChangeDirector.StandardChangeDirector.Update(TrackedObject项目)
在System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
在System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
在System.Data.Linq.DataContext.SubmitChanges()
编辑:
在分析时,问题似乎是在delete语句上生成的,类似于:
DELETE FROM [WorkItemUid] WHERE([OID] = 24151/*@ P0 /)和([WorkItemOid] = 745 / @ P1 /)和([SeriesInstanceUid] = '1.3.12.2.1107.5.1.4.54023.30000004101914490887500000063'/ @ P2 /)和([SopInstanceUid] = '1.3.12.2.1107.5.1.4.54023.30000004101913521221800001089'/ @ P3 /)和([完成] = 1)AND([FailureCount] = 0 / @ …
我们首先在Entity框架代码中工作
我们有一个课堂视频
class Video{
List<ImageInfo> Images{
get; set;
}
}
Run Code Online (Sandbox Code Playgroud)
我们的图像infoclass包含图像的路径和一些其他信息
class ImageInfo{
String path;
...
}
Run Code Online (Sandbox Code Playgroud)
我们希望在删除视频时让EF删除imageinfos
所以我们改变了模型构建器,如下所示:
modelBuilder
.Entity<Video>()
.HasMany(v => v.Images)
.WithRequired()
.WillCascadeOnDelete(true);
Run Code Online (Sandbox Code Playgroud)
我们不想在imageinfo类中添加回到视频的链接.
是否有可能在没有双向外键的情况下获得级联删除功能?
编辑
保存视频时,imageInfo的video_id不会填入数据库.
我们怎么解决这个问题?
我不知道它是否相关,但是当我们同时添加带有图像的新视频时,我们会收到此错误:
Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values.
Run Code Online (Sandbox Code Playgroud) 有人知道将大型SQL Server数据库转换为sqlite或SQL Server compact的最佳方法是什么?
SQL Server数据库应该在50-70Gb左右.
互联网上有一些例子(脚本模式),但我没有找到任何关于数据的结论.
谢谢.
非常直截了当的问题.我正在构建一个从SQL Server 2005实例读取数据的应用程序.我想在我的笔记本电脑上运行一些测试(没有SQL 2005),所以我正在考虑在本地数据库中交换以进行测试.
我正在使用VS2008,因此Compact Edition DB似乎是一个自然的选择.我原本希望换掉我的连接字符串,但似乎它只能让我使用SqlCeConnection而不是SqlConnection连接到CE数据库.任何方式,我可以在连接字符串中使用修饰符?
我有一个带有几个表的小型SQL CE 4.0数据库,使用Entity Framework 4进行映射.
这是我的代码
foreach (String designation in newItemDesignations)
{
ParameterData defaultValue = PDM.GetDefaultParameterData(designation);
// Fill the ItemParameterDBO object with the data
ItemParameterDBO dbParam = new ItemParameterDBO();
dbParam.ItemID = dbItem.ID;
dbParam.Designation = designation;
dbParam.High = defaultValue.High;
dbParam.Low = defaultValue.Low;
database.ItemParameterDBOes.AddObject(dbParam);
}
database.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
24 times每次newItemDesignations列表包含时,都会发生此代码exactly 525 elements.这总共需要12600行.
整个过程持续509 seconds.我猜这对12600行来说太多了.
我知道我在打电话SaveChanges 24 times.目前,应用程序设计不允许我将所有插入放入单个事务(with SaveChanges).但是,看看单个事务会发生什么.509 / 24 = 21 seconds或者a 40 ms per row. …
我正在尝试将Map控件中的快照作为WritableBitmap,将其转换为字节数组并将其保存在本地数据库中.它工作正常(我可以将字节数组转换回图像),直到我将更改提交给数据库.此时它会抛出异常"字节数组截断到8000的长度".我没有找到任何关于字节数组限制的文档.有谁知道如何增加8000的限制?我的字节数组是我的模型的成员:
private byte[] _locationImage;
[Column]
public byte[] LocationImage
{
get { return _locationImage; }
set
{
if (_locationImage != value)
{
NotifyPropertyChanging("LocationImage");
_locationImage = value;
NotifyPropertyChanged("LocationImage");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用SQL Server CE 4.0和Entity Framework 4.0的ASP.NET项目.它在我的本地计算机上工作正常.
但是,当我将它移动到远程服务器,并尝试登录到程序的管理部分时,我收到以下错误:
The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Run Code Online (Sandbox Code Playgroud)
它引用了远程服务器上machine.config中的以下行:
Line 237: <membership>
Line 238: <providers>
Line 239: <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
Line 240: </providers>
Line 241: </membership>
Run Code Online (Sandbox Code Playgroud)
现在,我的web.config中没有"AspNetSqlMembershipProvider"语句,它引用了一个名为"LocalSqlServer"的连接字符串.相反,我有以下内容:
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider" connectionStringName="PUGConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" applicationName="/" />
</providers>
</membership>
Run Code Online (Sandbox Code Playgroud)
这实际上在本地工作.连接字符串的名称是PUGConnection,而不是LocalSqlServer. …
asp.net asp.net-membership membership-provider sql-server-ce entity-framework-4
sql-server-ce ×10
c# ×3
.net ×2
asp.net ×2
database ×2
linq-to-sql ×2
asp.net-mvc ×1
config ×1
deployment ×1
insert ×1
sql-server ×1
sqlite ×1