How to setup local database from remote database in visual studio asp.net project? - sql

I am working on an ASP.NET project which accessing a remote SQL Server database. My objective is to set up this remote database on my local system.
I have tried 2 ways, but I'm facing problems both ways:
(1) Using SQL Server import and export wizard.
I get an error saying that the connection state is closed, but I am able to fetch all database tables of remote database:
(2) Schema and Data comparison from SQL Server object explorer inside of Visual Studio.
Here I get an error in that database user-related issues are showing. User or group not found:
I have tried other things in the last 4 days also but not found any clue to solve it. I am new to ASP.NET and SQL. Please help. Any helpful answer will always be appreciated. Thanks.
I have tried the Dennis1679's answer, but the following issues are coming.
One or more unsupported elements were found in the schema used as of
a data package. Error SQL71564:Error validating element[username]:
The element[username] has been orphaned from its login and cannot be
deployed.

Install SQL Server Management Studio, connect to the remote database, right-click on the database, choose export data-tier application. Then connect to your local instance and import data-tier application.
Connect to the remote database:
Right-click on the database choose export data-tier application:
Follow the wizard and save the .bacpac somewhere
Connect to your local SQL Server (localdb)\MSSQLLocalDB
Choose Import data-tier application
Select the previously saved .bacpac and import it. Now your local instance should have the same database

Related

Moving SQL Data into Azure SQL PaaS

I have a database in the SQL Server installed on Azure VM. DB Size is 2 GB.
How and what is the best approach to move all data into Azure SQL PAAS Service?
While the method posted by #Harris Xu is absolutely correct, I am adding the issues which I faced when I migrated my 500+ GB SQL Server DB from Azure VM to PaaS using .bacpac method.
Azure SQL DB is in a away limited when compared to On-prim SQL Server or SQL Server on VM's.
You will not face these issues while creating the .bacpac file but when you try to import, it might give some of the following compatibility issues.
Master Keys , Symmetric Keys, Service Queues and certificates cannot
be migrated to cloud. Drop them before preparing bacpac.
Drop orphaned Users.
If you are using XP_CMDSHELL, Trace Flags, DBCC commands or column store indexes, you got to remove them too.
Cross DB Queries are not allowed on Azure SQL DB. Remove all occurrences of ..
If you are calling an API from your stored proc then that too is not possible in Azure SQL DB. As a workaround you can use Logic Apps on Azure.
Moreover, Microsoft Migration assistant can help you find compatibility issues before hand too. You can download it here.
NOTE : This no way the full list of issues, I faced them because I was using all above features, if you are not using them you will not face them.
SQL Migration using data-tier application export/import (BACPAC)
The BACPAC file encapsulates the database schema as well as the data stored in a database application that can be simple imported to an Azure SQL Database.
Workloads using the source database need to be taken offline during the export process to ensure that the exported BACPAC file contains all data in a complete and consistent state.
Export to bacpac file in SQL Server Management Studio (SSMS)
You can follow this post.
Open and connect database file in SQL Server Management Studio (SSMS).
To export a database file, right click on the name of the database. In the context menu, select Tasks > Export Data-tier Application.
The option will open the wizard. Click Next> Introduction page and go to the Export Settings.
Import a bacpac file to Azure SQL
After you connect to your Azure sql, go to Object Explorer pane, right click the database, and select Import Data-tier.
The option will open the wizard. Click Next> Introduction page and go to the Import Settings.
The Import settings are requested to the bacpac file to import.

Not able to delete Azure SQL database

I have created one database from ssms 2017 version on azure sql server with .bacpac file, but when I am trying to access it from azure portal it is not showing under azure sql server instance. But when I am login into that instance with SSMS it is showing that database. Need help on this, can anyone face this problem.
regards
Sandy
I did the same operation successfully. I imported a new database with a BACPAC file to my Azure SQL Database. Please reference my steps:
connect to my Azure SQL Database instance with SSMS, right-click Databsse, choose Import Data-tire Application. I import the DB2 database from my BACPAC files.
Import Settings.
Complete the import. After the import job finished, we can see the database DB2.
Check the database on Azure Portal. Login my portal, choose the SQL server which our database instance host on in home page.
Click in the SQL server and we can find the new database DB2.
My SSMS version is the latest v17.9.1.
Hope this helps.
From azure portal I raise ticket regarding this issue, they solved my problem. Added my Azure Sql database to my subscription. During .bacpac file restore some issue occur due to which it wasn't show on portal. Also I am able to delete that datbase from SSMS generated delete script for database.

How to create Tabular Project for Analysis Services using REMOTE workspace server

I am trying to create a Visual Studio SSAS Tabular project connecting to a remote workspace server without success. I have no problem creating and deploying using localhost.
However I need the remote server to deploy to production or shared development server. I get error: "Cannot deploy model to the deployment database server 'xxxx.cloudapp.net'. Reason: You are not an Administrator on the deployment database server 'xxxx.cloudapp.net'."
I know I am reaching the server as otherwise the error is about not connecting to the server. I am already running Visual Studio as mydomain\adminuser and added it to the Analysis Server to make it administrator. However I am still getting that error. I can also connect remotely to the Analysis Server in Management Studio using that same user.
All the examples I've seen use localhost but have not found any using a shared/remote server even though some say it is possible without showing how. By the way, I understand using a local instance is better for development but I still need to deploy to a remote server. Hope that makes sense. Please help.
I ran into the same issue when trying to deploy a SSAS Tabular model remotely. The corresponding MSFT docs further even discourages to deploy to production via Visual Studio.
But, a viable alternative is to deploy via XMLA:
Create your SSAS Tabular Model in Visual Studio and use your local SSAS instance for your workspace database
Launch SSMS connecting to your local SSAS instance
Right-click on your workspace database, and select Script > Script Database As > CREATE to > File
Open the generated XMLA file, and a) replace the temporary workspace database name with the database name on the deployment server, and b) search for the database connection string and re-add the password (see the note here)
Launch SSMS connecting to your deployment SSAS instance
Open the XMLA file, and Execute it (by pressing F5)
Refresh the list of databases, right-click on the new one, and select Process Database
In case you already have a deployed database, then you need to select the ALTER to option instead of CREATE to in step 3 above.

Internal error import BACPAC file to windows azure sql database

I am using MSSQL2014 version CTP2.
Running my databases through Windows Azure SQL Database management.
I've created a BACPAC file via MSSQL of my local database and want to import it to Windows Azure.
I create the BACPAC file and upload it to my BLOBSTORAGE container.
In Windows Azure click SQL DATABASES
Bottom left click New
Click IMPORT
Choose my BACPAC URL which is the file contained in my BLOBSTORAGE
Name the DB and choose the server
Click the tick
I then get this error:
Error encountered during the service operation. Could not import
package. Internal Error. The database platform service with type
Microsoft.Data.Tools.Schema.Sql.Sql120DatabaseSchemaProvider is not
valid. You must make sure the service is loaded, or you must provide
the full type name of a valid database platform service. Internal
Error. The database platform service with type
Microsoft.Data.Tools.Schema.Sql.Sql120DatabaseSchemaProvider is not
valid. You must make sure the service is loaded, or you must provide
the full type name of a valid database platform service.
I can create a new database via Windows Azure which is fine but I'm trying to get my DB up because it has all my data in it.
What am I doing wrong?
I believe the issue was that I needed to assign the same DB owner to my db on my local machine as the one that was setup on my azure setup.

Connecting to SQL Server 2008 Express from VB 2008 Express

I'm using VB 2008 Express for our College Project. I'm also running SQL Server 2008 Express and have installed SQL Server Management Studio and used it to create my database.
Both software have been installed and running locally. I'm trying to connect to the database from VB 2008 Express. Database connection wizard have 3 options:
connecting to Access db
connecting to SQL Server 3.5 compact db and
connecting to SQL Server db file.
There are no problems connecting to the first two but when I try to connect to my SQL server DB file (.mdf) it throws the following error ("Unable to open the physical file .... Operating system error 32:(failed to retrieve text for this error. reason:1815.......an attempt to attach an auto-named database for file ...... .mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share")
I appreciate if anyone who had the same experience and overcome the problem could point me in the right direction.
Thanks very much.
Little Critter.
You need to detach your database from the server. Since you created the file there it is already running on the SQL Express server. Operating System Error 32 is a sharing violation and it means that the file is in use.
Try this:
Open Sql Express 2008 Managment Studio and find your database in the Object Explorer tree.
Right click on your database, choose tasks, and then select "Detach"
When the "Detach Database" dialog appears, select the checkbox that says "Drop Connections"
Click ok.
Your database should detach from the database server. Now the server will no longer bring that database up automatically and you should be able to get exclusive access to it.
Note that if you want to make more edits to the MDF you will have to reattach the database or you will need to use the tools built into VB 2008 Express. Because of this most people would choose to leave the database attached and not run it as a "User Instance". Check out this link for alternative ways to get to your data: How to: Access and Initialize Server Explorer/Database Explorer.
Anyway, you may have your reasons for setting it up this way. The steps outlined above should fix you up. Good luck with your project!