Convert .sdf database to .mdf database - c#

I have this SQL Server CE database (with more tables and data) which I would like to convert to SQL 2008 because I want use it in Server (application need to used by many). I am using SQL 2008 express and C#.
Please suggest how I can do this.

Have you tried the Data Migration Wizard?
Anyhow, you might find this interesting:
http://exportsqlce.codeplex.com/
Original source:
http://bembengarifin-tech.blogspot.com/2008/08/generate-script-export-data-from-sql-ce.html

This tutorial should help you. It shows you how to convert .sdf to .cs object using SQLMetal.exe

Maybe a good idea is to try microsoft (free) tool, Sql Server Management Studio :
http://www.microsoft.com/download/en/details.aspx?id=7593

Microsoft WebMatrix uses Compact SQL (.sdf file) by default. In the Database view, if SQL SVR is installed, there is a Migrate to SQL Server top menu item. There is also a menu selection to install SQL Server. Both WebMatrix and (a version of) SQL SVR 2008 are free to install.

You could use MSDeploy to migrate your database:
http://erikej.blogspot.com/2011/03/migrate-sql-server-compact-database-to.html

Related

trouble with initial setup and connection to microsoft sql server from Visual Studio

I am on a Windows 10 machine, which has Visual Studio 2015. I am now trying to do projects with a database on the same machine. I seem to have SQL server ( I am really new to Databases ) Here is why I think I have a Database, which I can use:
C:\Users\zohal>wmic product get name,version | findstr "SQL"
Microsoft SQL Server Compact 4.0 SP1 x64 ENU 4.0.8876.1
When I try to connect to a database from Visual Studio I do the following:
click on Project > Add New Data Source new Window Comes up
select Database new Window Comes up
select Dataset the only option available, new Window Comes up
select NewConnection new Window Comes up There are six options
select Micorsoft SQL Server new Window Comes up but the pulldown is blank. I looked in the services section of Computer Management application, and do not see a SQL service running. I want to know how do I connect to this SQL server and does it work for what I want to do, which is to run .Net C# code with SQL statements?
Update...........
Guys, thank you for the content and advice. I have tried both SQL compact and SQL Express, and ran into the following problems. I wonder if you can help, or perhaps I'll create a new post. I have tried everything I could think of. 1) I tried to use the SQL compact. Got as far as "Creating a SQL server Compact Database". When I right click on the "App_Data", I just don't see an option of "SQL Server Compact 4.0 Local Database" as it stated in the procedures. Here is an of what I see. I did a search online for this type of issue, and the solution was to install a tools package. I did that. In fact I ran the Visual Studio install file, and chose the modify option and added all the tools, and support packages I could think of. I rebooted the machine also; no change.
I also ended up installing SQLExpress, and followed this link to set it up, but when I click on a new connection option I do not see the SQL Express option in the server name pull down as it states in the procedure. I basically get as far as creating the project and three steps into the procedure. I can put the projects on Git if that helps. My immediate goal is to create a table and query it. Here the code in my project:
var query = from c in db.Customers
where c.City == "Nantes"
select new { c.City, c.CompanyName };
Right now, I get an error under "c" and "db" as I have not created a connection. While I don't know how to do that yet, I do know that is not a huge task. But if I can not connect to a Database, this does not help me much. I did find the right assemblies and added them to the beginning of my project. I am talking about
using System.Linq.Expressions;
using System.Data.SqlServerCe;
Just tell me what to do. Should post again or can help me?
Update: Thank you. The MVC .Net Core MVC procedures worked. Thank you so much.
SQL Server Compact is not a full fledged database service. It is a way to store data in a file and run sql like queries against it.
Here is a short walk through of how to connect to a sql compact database: https://msdn.microsoft.com/en-us/library/gg606540(v=vs.100).aspx
If you want to use an actual sql server you can download and install SQL Server Express for free. Here is a walk through for that: https://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
Both of the linked examples use Entity Framework to connect which is an ORM. There are many ways to connect to a database in C#. But since you mentioned running sql statements directly you may want to look into Dapper.Net which is a mirco ORM that let's you run SQL statements and map the results back to objects.
If you are not developing mobile (win mobile) apps, you need to download SQL server express edition which is suitable for any database application built for .NET and targeting the desktop/web apps.
To install the latest SQL express 2016, please visit this link or do some search on the web:
https://www.microsoft.com/en-us/sql-server/sql-server-editions-express
I would first verify in "Control Panel > Programs > Programs and Features" to check whether SQL Server is installed on the machine. You should see program with name "Microsoft SQL Server 20xx Setup". If you don't see any such names, then I suggest you to download and install a fresh copy of SQL Server.
Microsoft® SQL Server® 2014 Express
If you do see it in control panel, then open RUN (Windows Key + R) and type SSMS and press enter. This should open SQL Server Management Studio. (Sometimes SQL Server might be installed but Management Studio might not be. You can download Management Studio as well from the link provided above)
After opening management studio, enter the server name and click on "Connect". If you don't know server name enter . (dot) and click "Connect". Now you should be connected to SQL Server.
You should be able to connect C# code with SQL Server using a connection string.
Different formats of connection strings
How to store connection strings in web.config or app.config
Execute a command in c# by connecting to SQL Server

Use sdf database(SQL Server Compact 3.5 database file) without installing Microsoft sql server C#

I want to use a database in my C# program but I don't want other users who want to use my program to have to install a big volume software like Microsoft SQL Server that is more than 2 GB. So, can I use .sdf database (SQL Server Compact 3.5) without Microsoft SQL Server?
When I give my published software to anyone with a normal Windows 7 OS (that most probably does not have Microsoft sql server installed) he should be able to use my software without any requirements. My program is really simple, but involves saving data in a database.
I don't want users to be forced to install Microsoft SQL server !
SQLite may also be an option;
http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki
Used it on a project recently and works really well.
Try the site below, I've found it useful in the past. The subjects referenced there are still valid under Visual Studio 2008 / SQL Server Compact Edition 3.5.
http://arcanecode.com/2008/08/12/getting-started-with-sql-server-compact-edition-35/

Publish C# project with database

I'm currently learning C# with Visual Studio 2013 and planning to write an application with Database. There i have some questions:
What's the best database to publish with my application to
friends/customers? The database won't be too big. And every user
should use his own database.
How do i publish my application with the database and make an installer from it? I want to give customers a setup.exe that they can install. With everything they need, i.e. .net, database, etc
Thanks in advance
Here is a good SQL Comparison Table that shows what you can and can't have with different options (SQL Server Express, Local DB, SQL Server Compact / CE).
You probably want SQL CE so you can bundle up an actual database file with your installer.
As for the installer, you'll need to create a Bootstrapper which will contain your installer + other installers you require + your database that you're releasing (assuming you mean a pre-populated database?).
MS SQL Server Compact edition would be a good choice. It's free and redistributable with Your application. No extra installation needed. http://www.microsoft.com/de-de/download/details.aspx?id=17876
For really small databases, you could use sqlite.
Otherwise, I'd suggest using MS SQL Server, it has a free Express edition. I don't think attaching another install.exe would cause problems.

Connecting to a SQL Server database

I installed Visual Studio 2010 and SQL Server Express 2012. Then I created a new database in SQL Server Management Studio.
Can someone tell me how to connect to this database from Visual Studio (the type of project is not relevant) and start working.
Take a look at your Server Explorer. You will be able to create data connections, and use them, from there.
On the other hand, if you asking how to create a C# program and connect to your database, that's an entirely different question, with a far more complex answer. But a little research on Google should get you started. This article might help if this is what you want to do.
There are options like if you want to add and Entity Framework to your project or you want the simple to the point connection to the database.
Well, in the second case you can follow the steps:
Go to the server Explorer>>Options to add a conection to the database>> Choose the Server Name>> and you will be guided.
For using an Entity Framework, you can go through the Entity Framework Tutorial
I don't think you would be able to connect to SQLSERVER2012 database files from VS2010 server explorer due to the version incompatibility of the database files and the VS2010..

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

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.
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.
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.
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.

Categories

Resources