How to combine Entity Framework and SQL Compact in Visual Studio 2012? - visual-studio-2012

I am using the MS Entity Framework and Visual Studio 2012 in combination with the SQL Server Express. Now I want to use the EF in combination with an SQL Server Compact Edition database.
The design process will be model first.
I created an SQL CE database file in VS and started the design with a database model. I can create the .slqce file, containing the database schema definitions without any problems.
Actually my Problem is, that I can't find out how to execute this file on the database.
To test another approach, I created the database tables, columns... in the Server Explorer and used this to create an entity model. This worked well, but again, I don't know how to update the DB with changes, made inside the model.
What am I missing here?

You can use my SQL Server Compact Toolbox addin to create the database file and execute the script. You may need a modified template, as I describe here http://erikej.blogspot.dk/2013/02/fixing-entity-framework-designer.html

Related

Mvc5 database SQL, VS 2013

I need your help, I am doing Mvc project in VS 2013 with SQL database, I have created database first and then I complete my project, but now working on project I change data type of one column, and the run project, it gives this kind of error.
By "database first", I'm assuming you mean your using EDMX. The EDMX is a snapshot of your database at the moment is was generated. If you change something in your database, you have to regenerate the EDMX.

How to import data via post deployment script from SQL Server CE into a SQL Server DB freshly created using VS database project

I'm trying to import data from a SQL Server Compact (.sdf) database into a SQL Server database created through Visual Studio database project.
The .sdf database was created by a third party tool from an existant SQL Server database, and it is embedded into the Visual Studio project. The purpose is to deploy the database and insert initial values on a remote machine. I would like to run the import script as a post deployment script something like the following:
INSERT INTO Employer(
EmployerId,
EmployeeName
) SELECT
EmployerId,
EmployeeName
FROM sdfDB.dbo.Employer
Is it possible to reference a SQL Server Compact database (sdfDB)
in T-SQL script?
If not, what is the best practice to import data
into a freshly created DB from an embedded datasource which can be
deployed by build script in a remote machine?
1) Is it possible to reference a SQL Server Compact database (sdfDB) in
T-SQL script?
If you are thinking to something like this,
INSERT INTO [SQL SERVER Db].Table (Values)
SELECT (Values)
FROM [Sql Server Compact Db].Table
unfortunately no, this is not possible.
2) If not, what is the best practice to import data into a freshly
created DB from an embedded datasource which can be deployed by build
script in a remote machine.
You can use the SQL Server Compact Toolbox, that contains features to generate scripts from a Sql server compact file, that you can use to populate the SqlServer database.
Features:
Script!
Migrate a SQL Server Compact database directly to SQL Server (LocalDB/Express)
Migrate from SQL Server Compact to SQL Server, SQL Azure and SQLite via script (...)
(...)
EDIT
Also available in api form at exportsqlce.codeplex.com. Thanks ErikEJ for comment and great job!

Visual Studio 2012 SQL Database Project with SSDT

I'm starting to use Visual Studio 2012 with integrated SQL Server Data Tools and although I watched 2 of microsoft's video's on getting started with SQL Database Projects I'm still having trouble understanding how to work with them especially since I'm new to db development.
Some questions:
What is the difference between Importing a database or adding a reference to the database?
What is the difference between Server Explorer and SQL Server Object Explorer tabs? In one I can browse the database through localhost\SQLEXPRESS.dbname and the other goes through localdb\Projects. At what point are these synchronized?
How do I change the Target Database Name under the Project's properties?
1) Importing a data base creates a project that includes all of the databases artifacts. Adding a database as a reference allows a project to access the database. So if you have a SSDT project and a c# project that uses the db, the c# project gets the reference. You could choose to create the SSDT project by importing an existing db.
2) SQL Server Object Explorer is part of SSDT and allows you do perform online SQL development including creating new artifacts, adding data to tables, and executing scripts.
3) To change the target database name for debugging purposed (where the database goes when you build/debug) change the target connection string in the debug tab of the properties menu of the project.
I've found this link to be quite helpful.
There are many differences between SQL Server Object Explorer (SSOX) and Server Explorer. Here's a couple:
SSOX allows you to launch refactoring operations
SSOX provides a logical view of your source code in Solution Explorer
In short, SSOX targets database development whereas Server Explorer is (I think) a generic hierarchical viewer for many server types.
Regards
Jamiet

InstallShield 2012: Need to switch between sql scripts (sql server & oracle) based on property

The web applications I am installing can run against either a SQL Server or Oracle database. I need to be able to determine which database the user has (client is suggesting a property file) and then dynamically tell InstallShield whichSQL script to run, I know I can figure out how to determine which database is installed. My question is how do I configure the Feature/Component and tell InstallShield which script to use.
I don't have any Oracle servers available to me nor do I have the Oracle Instant Client. If I did, it seems I'd use a Basic MSI project included in InstallShield to build an Oracle Instant Client MSI and add it to my installer as a setup prerequisite. Kind of odd but I guess they couldn't get IBM / Oracle to play nicely.
So let's say I had all of that. I'd create a Sql connection that supported both MS and ORA SQL and build it. I'd run the installer with logging on and use the SQLLogin dialog to browse to a SQL instance and an Oracle Instance.
Then I'd look at that logfile and see if there's any evidence of the built-in InstallShield SQL custom actions setting a property that indicates the type and/or version of database server that it connected to. Hopefully something will surface because I didn't find anything in the documentation.
Once I figured that out, I'd use the property in a conditional expression so that the SQL scripts only ran on the type of database server they were intended.

change collation of DB SQL Server 2008

I have created some new databases in SQL Server 2008 Express (10.0.1600.22) and I have also restored one from SQL Server 2005 Express (9.00.1399.06).
The collations for these are different and I cannot execute queries across them as a result. So I am trying to change the restored database collation
from: SQL_Latin1_Genral_CP1_CI_AS
to: Latin1_General_CI_AS
However the new collation does not appear in the list of options. Not sure if this is possible.
BTW - workarounds that are not options:
I cannot script the data from sql server 2005 express (it seems - I may be missing something)
I cannot script the DB on 2K8 server as I get an out of memory exception when doing that :-(
If the collation is visible for other databases on your instance but not this specific one restored from a 2005 instance I wonder if the list displayed is dependent upon the databases compatibility model.
Maybe try changing the compatibility mode of the restored database to 100 to see if it appears in the list of options.
Note changing the database collation will not affect existing columns. Here's a script that may help with that.

Resources