Thursday, October 8, 2009

SQL Server Compact is not intended for ASP.NET development

The exception "SQL Server Compact is not intended for ASP.NET development" is thrown when you try to use a SQL Server Compact Edition Database on an ASP.NET web site. That's because, as the message says, SQL Server CE was not made to be used on ASP.NET, because of its several restrictions relating "normal" SQL Server editions. If you cannot install a Standart or Developer Edition SQL Server on your development machine, try using Express Edition. It has everything a developer needs and it's free.

If you really want to use Compact Edition, add the following to your Global.asax file and the exception will go away:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", True)
End Sub

11 comments:

  1. .net is one of the most user friendly software development platforms. ASP.net development gives the way to develop complex web applications and web pages. Even most of the Business Intelligence software are being made on .net platforms with integrating ASP.net as an essential functional part.

    ReplyDelete
  2. thanks to you very very much , your Answer

    AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", True)


    is very useful

    ReplyDelete
  3. Thank you! I was pretty worried when I saw the error as I was looking at a fairly large development to get round this.....one line of code is much better ;)

    ReplyDelete
  4. You're welcome. Just bear in mind that SQL Server Compact is targeted at a specific kind of applications (mainly mobile apps & desktop "non-adminitrator-user" apps), and because of that it has several restrictions if compared to other SQL Server Editions. The articles "Differences Between SQL Server Compact and SQL Server" (http://msdn.microsoft.com/en-us/library/bb896140(SQL.100).aspx) and "Compare SQL Server 3.5 Compact and SQL Server" (http://download.microsoft.com/download/A/4/7/A47B7B0E-976D-4F49-B15D-F02ADE638EBE/Compact_Express_Comparison.doc) give you a good idea on those restrictions. I suggest that you check out SQL Server Express too!

    Cheers,
    GB

    ReplyDelete
  5. Thank you so much for your entry.

    AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);

    I don't meet that error.
    It's very useful!

    ReplyDelete
  6. Very useful SQLServerCompactEditionUnderWebHosting, the problem with express is that database file encryption is not supported. So if you need to encrypt your data then you either need SQL Server enterprise edition which costs zillions, or something like SQLite.net, compact edition is great for a web site with minimal database requirements. But i dont think connection pooling works, you may need a singleton to hold your SqlCeConnection open.

    ReplyDelete
  7. Thank you so much for the solution! You saved my day ;-)

    ReplyDelete
  8. Where exactly do I put this code? I get a lot of errors regardless of where I put it.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete