views:

218

answers:

3

Is there any way to do this?

Update: Sorry, I should have included more information. I am trying to create and connect to a SQL CE database using System.Data.SqlServerCe in C# running on a PC (i.e. not running on a Windows Mobile device).

This code:

string connstr = "Data Source=\"" + 
    filename + "\";Persist Security Info=False;";
System.Data.SqlServerCe.SqlCeEngine engine = new SqlCeEngine(connstr);
engine.CreateDatabase();

... works fine on any PC that has SQL Server 2005 installed, but fails on any PC that doesn't have it installed. I'm trying to find out if there's any way to get this to work without installed SQL Server 2005 on the machine.

+2  A: 

You can do it with Visual Studio - when you add a connection, change the data source from Microsoft SQL Server to Microsoft SQL Server Compact 3.5.

Also, if you mean the actual server - as opposed to the management tools - then SQL Server 2008 Management Studio [Express] can open SQL CE databases directly.

Edit: To create the database in Visual Studio, choose "Local Database" when you go to add a new item. That's a SQLCE database. And in SSMS[E], when you choose the SQL Server Compact option, you can choose "New Database" as an option in the Database File drop-down.

Edit2: In order to have code written against SQL CE run successfully on a vanilla target machine, you will need to install something on it, although not SQL Server 2005. SQL CE is a separate product (download page). It should also appear as a redistributable module in Visual Studio if/when you create an MSI installer for your product.

Aaronaught
Sorry, see my update.
MusiGenesis
@MusiGenesis: See my update. :) What you're seeing is probably a coincidence, in that the machines that have SQL Server 2005 also have SQL Server CE; the latter does not depend on the former in any way.
Aaronaught
+1  A: 

Just to add to what Aaronaught was saying, to connect to a SQL CE database programmaticaly, you don't either need SQL Server installed. CE runs in proc, and as long as the SqlCE dll's are installed (their part of the framework nowadays) then you should be able to connect to it without any issues.

BFree
Sorry, see my update.
MusiGenesis
+1  A: 

I assume that what you mean is can you create one with a tool, rather than with code. Studio can create them just by going to the Server Explorer and adding a new connection (you'll get the option to create one).

If you're looking for something a little nicer or something that doesn't require Studio, then Primeworks' Data Port Console is a really nice tool.

EDIT

If you need to create it through code then yes, you can still do this without Server installed. Make sure that you have the SQL CE Redistributable binaries (for the proper 32/64bit) deployed to the target and in a place the app can find them.

See locally at

C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5

or online.

ctacke
Sorry, I meant create one with code. I just found out a client's production machine isn't licensed for SQL Server 2005, so I'm scrambling to find some way to get SqlCE to work on it anyway, or replace it (Oracle Lite is already out, and I'm looking at SQLite).
MusiGenesis
That will definitely work? I tried copying over the 7 sqlce... DLLs into the SYSTEM32 folder on the server, but that didn't work. I need to to a full install of sql ce?
MusiGenesis
100% positive. We have a desktop app that uses SQL CE for data collection and error storage and that's all we do ios include the binaries with our app installer. Works for 32 and 64 bit, no problem.
ctacke
FWIW, I never put them in System32, I put all of the native binaries and the managed assembly right in my app folder.
ctacke
Whew, thanks. I just ran the 3.5 installer on the server and everything's working fine. Have you ever used SQLite? Do you know how it compares in terms of file size and speed? Also, is my memory failing me in thinking that SQL Server 2005 used to be a requirement for SqlCE on the desktop? Or am I just thinking of RDA?
MusiGenesis
SQL Server has never been required (except for RDA or replication).I have used SQLite. I'm not a fan because you can't use TableDirect and it immediately makes future replication a non-option.
ctacke