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

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!

Related

Cannot connect to Azure SQL Data Warehouse database-error "Incorrect syntax near 'ANSI_NULLS'"

I could successfully deliver the new Azure SQL Data Warehouse database.
If Í try to connect to the SQL Data Warehouse Database, I receive following error message:
"Parse error at line: 1 ,column: 5: Incorrect syntax near 'ANSI_NULLS'".
This happens in VS 2013 and VS 2015! The data load process with BCP to the SQL Data Warehouse database was successfully!
Thanks, Herbert
Azure SQL Data Warehouse does not currently support setting ANSI_NULLS on (SET ANSI_NULL ON). You can simply remove that statement from your query and you should have success.
Additionally, make sure that you are running the June 2015 Preview of SSDT (http://blogs.msdn.com/b/ssdt/archive/2015/06/24/ssdt-june-2015-preview.aspx). This has the supported SSDT capabilities for SQL Data Warehouse.
I had the same error, when tried to Use Visual Studio to query Azure SQL Data Warehouse 
 and selected my database.
The Workaround was to select master database, connect to it, then in top drop-down for the query change to my database.
I think your connection isn't actually recognised as a SQL DW connection. I bet your query window is a .sql file, not a .dsql as it needs to be. If you connect as a .sql query, it will try to set various settings that aren't supported.
Go back into the Azure portal and use the link to connect using SSDT from there. You should get a connection in the SQL Server Explorer pane which looks different, and when you start a New Query based on it, you should get a .dsql window, not a .sql one.

Creating SQL Agent JOBs in SQL Server 2012 Database Projects from VS 2012

I am working on Visual Studio 2012 with Update 2 + SQL Server Data Tools and I am able work on the SQL Server Database Projects.
How do I create/add new SQL Agent JOB into this database project? Because if I click Add - New Item... I don't see anything for Job.
I know Jobs are related to SQL Server and the Database Project is related to a SQL Database. But I was wondering how do manage the SQL Jobs?
Thanks,
Prabhat
Jobs aren't supported natively. It might be possible to add these from the post-deployment script, although it's not something I've tried.
Creating server agent objects are not supported by visual studio database projects; however you can add your job by calling dbo.sp_add_job stored procedure.
The easiest way will be:
Create your job by SSMS and copy the script.
Control the job is already exist at database or not at your post deployment script. if it is exist delete at first; or you are going to have an error during deployment. you can do something like below:
DECLARE #JobID BINARY(16)
SELECT #JobID = job_id
FROM msdb.dbo.sysjob
WHERE (name = N'NameOfYourJob')
IF (#JobIDdel IS NOT NULL)
BEGIN
EXECUTE msdb.dbo.sp_delete_job #job_name = N'NameOfYourJob'
END
Paste your script for creating job to post deployment script.
For feeling more safe you can check the job is working at the moment or not and
you can disable job also before deleting.
Disable a job
Check job status

How to combine Entity Framework and SQL Compact in 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

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.

Cannot open new .mdf file to C# project

I cannot attach a new Service based database(.mdf) to a C# project that I started. It shows:
Connections to SQL Server Database file(.mdf) require sql server 2008 express to be installed and running on a local computer.The current version of the SQL express can be downloaded.
But I already have SQl Server 2008 R2 installed.I've learned that a .mdf file cannot be "just" attached if the SQl server is a full version, then do I have to create a new database to accomplish the task?Or is there anything else that I can do?
As it's mentioned by Mostafa you should go to Tools->Options->Database Tools->Data Connections->SQL Server Instance Name and blank the SQLEXPRESS in that field. actually there is no need for instance name just blank it.
Use the VS 2010 menu Tools/Connect to database and, in the dialog that opens, fill the field "Attach a database file". AFAIK it's a known problem of VS 2010.
The visual studio has a default sql server instance name to connect to. The installer sets it up to point to the SQL Server Express by default. You have to change the Tools->Options->Database Tools->Data Connections->SQL Server Instance Name to point to your installed SQL Server instance name.

Resources