Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > Deploying SQL Server CE with a ClickOnce application
 

Deploying SQL Server CE with a ClickOnce application

Does anyone know how to deploy SQL CE with a Clickonce app? I have it in my application files but it doesn't end up on the client machine. Thanks!
Greg H.
Robert Abbey Inc.  Tuesday, June 02, 2009 1:41 PM

The first 7 dll's are required in order to use a SQLCE database, but they are not referenced directly anywhere in your project.

I think the System.Data.SqlServerCe.dll shows up in the references for your project if you are using a SQLCE database. In that case, you need to track down the dll and copy it into the project root, add it to the project, and then delete the reference to the one in the GAC and point it at your local one.

The easiest way to get the dll is to first look under References and find it, and set "copy local" to true, then do a build. Then you can pick it up out of the bin folder.

By the way, here's a thread with a reply of mine that discusses how the database gets deployed, and offers some ideas about how to handle updates to it and so on. I don't know if you've gotten to this point yet, but the two threads that I reference in the post found at this link will probably be helpful to you.

http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/c8c55be6-be34-47cf-93fc-6cc0bf97f2cf

RobinDotNet


Click here to visit my ClickOnce blog!
RobinDotNet  Monday, June 08, 2009 1:26 AM
Hi Robert,


Here is the walkthrough: How to publish/deploy WinForms application including a SQL Compact database file (*.sdf)via ClickOnce?


1) Create a new Windows Forms application.


2) Add Data Source (select a database file such as Northwind.sdf) to your project.


3) Project menu -> Add Reference -> .NET tab -> Locate and add the assembly "System.Data.SqlServerCe.dll" to your project

4) Copy the assembly "System.Data.SqlServerCe.dll" to your project
Click "Show All Files" icon button on Solution Explorer -> Unfolde References node -> Highlighten the assembly"System.Data.SqlServerCe" -> Set its "Copy Local" property value as True.

5) Drag&drop DataGridView1 onto Form1, and using |DataDirectory| path in connection string.
Code sample:
6) Select Northwind.sdf file in Solution Explorer and look at its properties:
Make sure the "Build Action" property is set as "Content".

Imports System.Data.SqlServerCe

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim scon As SqlCeConnection = New SqlCeConnection("Data Source=|DataDirectory|\Northwind.sdf")
        Dim ceda As SqlCeDataAdapter = New SqlCeDataAdapter("Select * from shippers", scon)
        Dim ds As New DataSet
        ceda.Fill(ds, "MyTable")
        DataGridView1.DataSource = ds.Tables("MyTable").DefaultView
    End Sub

End Class

The "Copy to Output Directory" property is set as "Copy if newer".


7) Project Property -> Publish tab -> Press "Application Files" Button

Check the database file Northwind.sdfin list, and make sure its “Publish Status�is set as “Data File (Auto)�and “Download Group�is set as �Required)�3

8)
Project Property -> Publish tab -> Click “Publish�button to publish your application.


The database file will be deployed with application in "Data" folder of application Installation folder. An exe.config file will also be deployed along with application in application Installation folder.


The SQL Server Compact Edition installation on client machine is optional.


Best regards,
Alizee Hayek


WIth REgards, Alizee Hayek
Hayek  Tuesday, June 09, 2009 3:40 PM

You can actually deploy SQLCE by including all of the dll's rather than deploying it as a prerequisite. Add each of the dll's to the top level of your project, set "build action" to "content" and "copy to output directory" to "always". Here's the list of dll's:


sqlceca35.dll
sqlcecompact35.dll
sqlceer35EN.dll
sqlceme35.dll
sqlceoledb35.dll
slceqp35.dll
sqlcese35.dll

You also need this one: System.Data.SqlServerCe.dll
If this is in the references (I can't remember if it is), you will need to delete the reference and re-add it, pointing it at the one you have included in the project by browsing rather than using the .Net tab in the Add References dialog.

RobinDotNet


Click here to visit my ClickOnce blog!
RobinDotNet  Wednesday, June 03, 2009 6:13 AM

Hi Robin, this is interesting!

Could you clarify, though:
You also need this one: System.Data.SqlServerCe.dll
If this is in the references (I can't remember if it is), you will need to delete the reference and re-add it, pointing it at the one you have included in the project by browsing rather than using the .Net tab in the Add References dialog.
Are you saying that System.Data.SqlServerCe.dll needs to be copied out ofSQL CE'sProgram Files folder and into the project root?

Thanks,
Jeff
InteXX  Wednesday, June 03, 2009 6:48 PM
Hi Robert,

Where did you check out the database file, and got to know it's not installed on the client machine? Actually, the database file will be copied to the data file folder of the clickonce download cache. So it's not in the same folder with the executable files.

Please also refer to this KB article for more aspects of deploying SQL Server CE databases with ClickOnce technology.


Best regards,
Bruce Zhou


Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Thursday, June 04, 2009 5:27 AM

The first 7 dll's are required in order to use a SQLCE database, but they are not referenced directly anywhere in your project.

I think the System.Data.SqlServerCe.dll shows up in the references for your project if you are using a SQLCE database. In that case, you need to track down the dll and copy it into the project root, add it to the project, and then delete the reference to the one in the GAC and point it at your local one.

The easiest way to get the dll is to first look under References and find it, and set "copy local" to true, then do a build. Then you can pick it up out of the bin folder.

By the way, here's a thread with a reply of mine that discusses how the database gets deployed, and offers some ideas about how to handle updates to it and so on. I don't know if you've gotten to this point yet, but the two threads that I reference in the post found at this link will probably be helpful to you.

http://social.msdn.microsoft.com/Forums/en-US/winformssetup/thread/c8c55be6-be34-47cf-93fc-6cc0bf97f2cf

RobinDotNet


Click here to visit my ClickOnce blog!
RobinDotNet  Monday, June 08, 2009 1:26 AM
Hi Robert,


Here is the walkthrough: How to publish/deploy WinForms application including a SQL Compact database file (*.sdf)via ClickOnce?


1) Create a new Windows Forms application.


2) Add Data Source (select a database file such as Northwind.sdf) to your project.


3) Project menu -> Add Reference -> .NET tab -> Locate and add the assembly "System.Data.SqlServerCe.dll" to your project

4) Copy the assembly "System.Data.SqlServerCe.dll" to your project
Click "Show All Files" icon button on Solution Explorer -> Unfolde References node -> Highlighten the assembly"System.Data.SqlServerCe" -> Set its "Copy Local" property value as True.

5) Drag&drop DataGridView1 onto Form1, and using |DataDirectory| path in connection string.
Code sample:
6) Select Northwind.sdf file in Solution Explorer and look at its properties:
Make sure the "Build Action" property is set as "Content".

Imports System.Data.SqlServerCe

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim scon As SqlCeConnection = New SqlCeConnection("Data Source=|DataDirectory|\Northwind.sdf")
        Dim ceda As SqlCeDataAdapter = New SqlCeDataAdapter("Select * from shippers", scon)
        Dim ds As New DataSet
        ceda.Fill(ds, "MyTable")
        DataGridView1.DataSource = ds.Tables("MyTable").DefaultView
    End Sub

End Class

The "Copy to Output Directory" property is set as "Copy if newer".


7) Project Property -> Publish tab -> Press "Application Files" Button

Check the database file Northwind.sdfin list, and make sure its “Publish Status�is set as “Data File (Auto)�and “Download Group�is set as �Required)�3

8)
Project Property -> Publish tab -> Click “Publish�button to publish your application.


The database file will be deployed with application in "Data" folder of application Installation folder. An exe.config file will also be deployed along with application in application Installation folder.


The SQL Server Compact Edition installation on client machine is optional.


Best regards,
Alizee Hayek


WIth REgards, Alizee Hayek
Hayek  Tuesday, June 09, 2009 3:40 PM
The problem with this is (a) I don't think you can deploy just the one dll -- have you tried that on a machine you don't have SQLCE installed on for dev? (b) you haven't addressed the problem of updating the database. If you even OPEN the SQLCE database to look at the structure, it re-timestamps it, and it gets deployed as a new version, essentially wiping out the customer's data unless you are handling this occurrence.

RobinDotNet
Click here to visit my ClickOnce blog!
RobinDotNet  Tuesday, June 09, 2009 5:00 PM

If you dont want sqlserver ce on clients machine then follow these steps. I hope this will help... :)


1) Create a new Windows Forms application.

2) Add Data Source (select a database file such as Northwind.sdf) to your project.


3) Project menu -> Add Reference -> .NET tab -> Locate and add the assembly "System.Data.SqlServerCe.dll" to your project

4) Copy the assembly "System.Data.SqlServerCe.dll" to your project
Click "Show All Files" icon button on Solution Explorer -> Unfolde References node -> Highlighten the assembly"System.Data.SqlServerCe" -> Set its "Copy Local" property value as True.

*Remark: If you dont want sqlserver ce on your client machine then you shld add 7 dll's and set their build Action proprtyto "content" ncopy to output directry property to "copyalways".

sqlceca35.dll
sqlcecompact35.dll
sqlceer35EN.dll
sqlceme35.dll
sqlceoledb35.dll
slceqp35.dll
sqlcese35.dll


5) Drag&drop DataGridView1 onto Form1, and using |DataDirectory| path in connection string.
Code sample:
6) Select Northwind.sdf file in Solution Explorer and look at its properties:
Make sure the "Build Action" property is set as "Content".

Imports System.Data.SqlServerCe

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim scon As SqlCeConnection = New SqlCeConnection("Data Source=|DataDirectory|\Northwind.sdf")
        Dim ceda As SqlCeDataAdapter = New SqlCeDataAdapter("Select * from shippers", scon)
        Dim ds As New DataSet
        ceda.Fill(ds, "MyTable")
        DataGridView1.DataSource = ds.Tables("MyTable").DefaultView
    End Sub

End Class

Remark:The "Copy to Output Directory" property is set as "Do not copy".


7) Project Property -> Publish tab -> Press "Application Files" Button

Check the database file Northwind.sdfin list, and make sure its “Publish Status�is set as “Data File (Auto)�and “Download Group�is set as �Required)�3

8)
Project Property -> Publish tab -> Click “Publish�button to publish your application.


The database file will be deployed with application in "Data" folder of application Installation folder. An exe.config file will also be deployed along with application in application Installation folder


WIth REgards, Alizee Hayek
Hayek  Tuesday, June 09, 2009 5:37 PM
Good luck with that. I have tested mine in a VM, and you can not avoid deploying the Sql.Data.SqlServCE dll even if you include the other seven. And I had to include the other seven as well, or it would not work.

Additionally, you're still not dealing with the problem of the database being updated and/or replaced when the structure is edited. :-)

Have a great day!

RobinDotNet
Click here to visit my ClickOnce blog!
RobinDotNet  Tuesday, June 09, 2009 9:20 PM
Hi Robert,


How's your problem now? Did you try our suggestions? If the problem still can't be solved, please let us know.


Best regards,
Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.
Bruce.Zhou  Thursday, June 11, 2009 5:27 AM

You can use google to search for other answers

Custom Search

More Threads

• Detecting InstallAllUsers value
• Change the installation path of applications
• Error 1324: The folder path 'n/a' contains an invalid character?!
• ClickOnce Performance Questions
• timeout to ntd winform
• Deployment project doesn't use correct icon under Vista
• Rant: .Net Code Access Security Sucks!
• Installing a service and modifying settings
• CustomActionData - /TARGETDIR="[TARGETDIR] " Requires Trailing Space
• Creating an upgrade MSI