Test Stored Procedure against data in Database project - sql-server-data-tools

I am using ssdt in VS2012. I am writing a stored procedure and now I want to test this SP against some data.
How can I do it without creating this SP on actual SQL Server Instance?

Is there any reason you don't want to build the database? This can be done without having to use a full SQL Server instances as SSDT comes packaged with LocalDB. Press F5 to build a database from your database project and add some data to the resulting database.

Related

Is it possible to easily migrate data from light SQL Server Express to Azure with a dacpac file?

I'm currently trying to deploy a website with Azure which I did following these steps
https://learn.microsoft.com/en-us/visualstudio/get-started/csharp/tutorial-aspnet-core-ef-step-05?view=vs-2019#publish-to-azure-app-service
however the data from the database didn't get saved, like it did in the video. I think this may be because I have 2 data contexts; one for users and one for general app models.
I believe I have to figure out how to migrate my data from SQL Server Express provided by Entity Framework to Azure.
It seems like it should be doable from this link
but then this one makes it sound like you need a .bak file.
Just want to know if my Visual Studio data can easily transferred to Azure this way. would it be easier to publish my "data tier application" or extract and copy what I need to azure. Kind of overwhelmed at all the documentation trying to find the easiest way the small amount of data for my test website.
How to migrate my data from SQL Server Express provided by Entity Framework to Azure?
No you can not do that, import and export feature is not available with SQL Server Express. You can reference this link: Limitations of SQL Server Express.
As you posted the screen shoot, no function can help you migrate the database to Azure.
So if you really want migrate the database from local SQL Server to Azure, you'd better using the Microsoft SQL Server Management Studio(SSMS). There are so many ways, such as:
Migrate on-premises SQL Server or SQL Server on Azure VMs to Azure SQL Database using the Data Migration Assistant
Tutorial: Migrate SQL Server to a single database or pooled database in Azure SQL Database offline using DMS
Copy data to and from SQL Server by using Azure Data Factory
Migrating SQL Database to Azure SQL Database using SSMS Export/Import
If you are first time to migrate, we suggest to you use the Azure Data Migration Assistant as Alberto Morillo said.
Hope this helps.
Before trying to migrate the database to Azure you need to first verify the database and its objects are compatible to Azure SQL Database. If you don't do that the migration may fail.
My suggestion is to use Azure Data Migration Assistant (DMA) to perform an assessment of your database and make sure there are no blocking points that can make the migration not possible. Make adjustments based on the report generated by the DMA tool and then use any migration method (including extracting\importing a Data-tier Application) to migrate your database to Azure SQL Database. DMA can also migrate your database to Azure SQL Database and for me is the easiest way to do it.
About restoring a native backup to Azure SQL Database, that is not possible. You can export your database as bacpac and then import it to Azure SQL Database, or you can use DMA or Data Migration Service to migrate your databases to Azure SQL Database.
Adding to what is already said . You can dump all the data in txt or csv file and put that in the local drive . In Azure we have the Azure data factory (ADF) , which has a copy activity , this is very powerful and looks like will be good for your scenario . As mentioned before the data types are the key . You will have to install something called integrated Runtime ( IR ) and it should work .

Publish ASP.NET project with local data on Azure

I'm quite new to ASP.NET and I encountered a problem when publishing my project to Azure. After configuring the connectionStrings in Web.config, I have successfully uploaded my local database structure to Azure. However, all tables on Azure are now empty, without any local data. So how can I upload both the database structure as well as the data in it? Thanks in advance.
To migrate an existing SQL Server database to Azure SQL Database you can export the schema as a TSQL script and then execute that script against Microsoft Azure SQL Database as follows:
1.Open SQL Server Management Studio and connect to an instance of the Database Engine.
In Object Explorer, right click a database to open a menu, select Tasks…, and then select Generate Scripts.
2.Choose objects to export.
3.Set scripting options. You have the options to save the script to file, clipboard, new query window; or publish it to a web service.
4.Set advanced scripting options.
You can also set the Types of data to script to one of the following based on your requirements: Schema only, Data only, Schema and data.
5.After the script is created, you have the option to modify the script before running the script against an Azure SQL Database to transfer the database.
You can now run this script on your Azure SQL Database.
For more details, you could refer to this article.
You have to create a post deployment script. If the tables are created just fine on your azure application, then you must define what default data they will have. So in your post deployment script you will insert the data you want.

Exporting ASPNETDB.MDF to an external database

ASP.Net 4.0/C#/MSSQL/Microsoft SQL Server Management Studio
Hey I am now at the stage where I want to move a project to a live server
Now I want to move the tables from the ASPNETDB file in the App_Data folder
to the server.
I have used the Aspnet_regsql.exe tool to successfully generate the following tables
on my shared hosted server
dbo.aspnet_Applications
dbo.aspnet_Membership
dbo.aspnet_Paths
dbo.aspnet_PersonalizationAllUsers
dbo.aspnet_PersonalizationPerUser
dbo.aspnet_Profile
dbo.aspnet_Roles
dbo.aspnet_SchemaVersions
dbo.aspnet_Users
dbo.aspnet_UsersInRoles
dbo.aspnet_WebEvent_Events
Now what is the next step to essentially copy the tables from ASPNETDB.MDF
to these tables on the server?
Many thanks =)
What version of SQL server have you got?
If you can open the database locally in SQL Management Studio you can just use Generate Scripts that you can then simply open and run on your production server. It has the option to copy
Data
Schema
Both
So you can start with an empty database on Production and copy both the data and schema at once with a single .sql file and you'll be good to go.
You can use the export data feature from the management studio to migrate the data from the msf file to the live dtabse.
You are really better off putting all the membership etc. tables, views and stored procs into the main database for your production application. You can do this with the Database Publishing Wizard, which will create a script to recreate everything including all the data. No need to use two separate databases.
Alternatively, one can run this exe to copy empty tables from ASPNETDB.mdf to external SQL server.
drive:\WINDOWS\Microsoft.NET\Framework\versionNumber\aspnet_regsql.exe

How do I migrate a SQL MDF File to a production SQL Server? (ASP.NET)

I have an ASP.NET project that also uses a SQL MDF File. My target server is SQL 2008R2 or SQL Azure.
I would like to know what deployment options I have as I migrate from DEV to PROD. In case it matters I'm not under any regulation to maintain PII or similarly private data.
How do I move my test schema and perhaps data to production?
You can move the entire database, including the data by attaching the MDF file to the new SQL server. Otherwise you can select all objects and generate CREATE scripts to copy the schema over.
Yes, you can attach to the MDF file directly, or do a backup / restore to get it over to SQL Server 2008.
I haven't played with SQL Azure... From what little I've heard I think you might be stuck scripting the data as durilai suggested (last I heard we're not allowed to do backups / restores for SQL Azure).
In SQL Server Management tools, right click on the database and click 'Script Database As' to create an SQL script for your database. You can also do something similar at the table level if you want the data.

Data-Tier Projects and Linked Servers

I'm trying to use a Data-Tier application involving a linked server and running into an odd problem.
Here's what I have:
1) A VS2010 solution which includes a Data-Tier project.
2) The Data-Tier project targets an SQL 2008 R2 server.
3) The SQL server has a working linked server connection to an Oracle database.
4) Views within the Data-Tier project reference the linked server using OPENQUERY
The linked server connection is valid, running queries against it on the server work fine, and creating the views directly on the server works fine as well.
However, whenever I attempt to build my Data-Tier application I get the following error:
SQL03006: View: [dbo].[vwMyExampleView] has an unresolved reference to object [MyExampleLinkedServer].
Essentially the problem is that the SQL Server Database project doesn't have a way to resolve the Link to the Oracle database's tables.
I had a similar problem when trying to reference a table in a different database on the same server. In my case I was using SQL Server for both databases, and created a database project for the other database, added it to the solution for the first project, then created a reference to the second project from the first. I also used SQLCMD variables in synonyms so that I would be able to change the synonym, and all my proc and view references would not need to be updated.
I'm not sure this will work between SQL Server and Oracle since the Visual Studio database edition only supports SQL Server. (AFAIK) You may be able to find a solution by creating a .dbschema file and adding the Database reference to your SQL Server project.
More details can be found at this link:
http://msdn.microsoft.com/en-us/library/bb386242.aspx
In SQL 2012, just add new item-> Server Objects - > LinkServer, add the sp code that creates link server, you are good to go

Resources