Tutorial :Can I create and connect to a SQL Server CE database if SQL Server 2005 isn't installed?



Question:

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.


Solution:1

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.


Solution:2

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.


Solution:3

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »