Database backup of azure database deployed in local sql server management studio - c#

Can anyone help me in doing this task? I am using my sql azure database in my local machine's sql server management studio 2008 r2. What my issue is, I am trying to take backup of a database from my c# console application using the following methods:
using smo: showing error at "sqlBackup(server)" method.
The error details like -
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Microsoft.SqlServer.Management.Smo.SqlPropertyMetadataProvider.PropertyNam
eToIDLookupWithException(String propertyName, PropertyAccessPurpose pap)
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.GetDbComparer(Boolean inSe
rver)
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.InitializeStringComparer()
at Microsoft.SqlServer.Management.Smo.AbstractCollectionBase.get_StringCompar
er()
at Microsoft.SqlServer.Management.Smo.SimpleObjectCollectionBase.InitInnerCol
lection()
at Microsoft.SqlServer.Management.Smo.SmoCollectionBase.InitializeChildCollec
tion(Boolean refresh)
at Microsoft.SqlServer.Management.Smo.SmoCollectionBase.GetEnumerator()
using "backup database" command, this showing command not supported in this version of sql server. After searching in internet, i found that this command wont support for azure databases in ssms.
Can anyone please provide me solution to solve this.

You can not backup the Database in Azure Sql Service. When try to Backup Shows this Error
Statement 'BACKUP DATABASE' is not supported in this version of SQL Server.
So Backup Azure SQL Service by
Right Click on Db --> Tasks --> Export data Tier Application --> Set Location
Creates a bacpac file after export, then it can be import via this
Note: Be aware there are export and extract. The extract option only copies the schema, so if you need the data as wel make sure to use the export variant.

For security reasons, SQL server instance doesn't allow database migrations between two different target servers such as local and azure or vice versa.
The below tool can help run the scripts on one server to another. Keep in mind that when you run them it restores the schema and the data fully. You can alter the settings in Advanced option.
https://sqlazuremw.codeplex.com/

Related

How to bake in the databases from SQL Server to C#

I'm very very new to SQL Server, and I have written a program in Visual Studio using C# that uses a table from a database that I have created using SQL Server Management Studio. But if I try to run my program on another device, it either asks for a version of SQL Server to be installed or it fails to connect to the server because I used the local option to create the said database and therefore, the other device doesn't have the permission to connect to it.
I have read somewhere that I should use in-memory databases so that other devices can run this program without connecting to me or needing SQL Server to be installed? Can I store the database somewhere in the project and tell my program to seek it and load it?
TLDR; how to use the features of SQL Server like database and tables while offline and without the need to connect to any server or even the need to install SQL Server itself if possible.
And sorry for my bad English!

Access SQL Server database without SQL Server service

My C# .NET (4.5.2) application accesses a local SQL Server (13.0.1601) database.
For data archival purposes my client wants to pack a snapshot of the program and the database in a folder to run the old state when needed.
How can this be achieved with no running SQL Server service but only the folder contents and an installed .NET runtime?
Options considered so far are exporting the database to .bak or .csv and putting them in the folder, but those seem to involve a lot of manual labor.
As mentioned in the comments by marc, you need to have a SQL instance running to use a backup file.
Exporting it to a .bak file is not a "lot of work" - it just involves logging in to the SQL Server (from the application) and issuing the right SQL commands.
But in order to view this again you will have to re-import it back into a SQL instance - this is the reverse of the step above (although obviously you will have to rename it because your original database will still be resident in the SQL instance).
If you are looking to avoid having a SQL instance (service) installed then maybe SQL Server Express LocalDB is an option for you - it runs totally in memory.
You could create a script to export the tables as CSV and modify the program to use q to run its sql queries directly to those CSV files.
There is no embedded version of SQL Server. The closest thing is the LocalDB feature available since the 2012 version - it does require installation of some SQL Server components but does not require running a service. With it installed, you'd attach the MDF and LDF files (read-only if necessary) of the snapshot.

Visual Studio 2012 move local .sdf file to server computer

here is the problem I am facing now. I have created an application that uses local database (this was created by Add -> New Item -> Local Database. Afterwards I have added tables under this .sdf database.
Then I have connected to this database using Add -> New Item -> ADO.NET Entity Data Model.
Everything works like a charm, unless I was asked to move this database to a place, where multiple people could access this database and work with it.
Therefore, as I have no previous experience with databases, I have treated this .sdf file as any other file (let's say Excel workbook) and I thought that I could simply take already existing database, copy it on server computer (e.g. \Server001\Database\Database1.sdf) and simply change connection string under app.config.
However the problem is that this does not work. As I didn't know how to change connection string, I created new application, where I have tried to connect to this database located on a server computer; however I received the following error:
SQL Server Compact does not support opening database files on a network share.
I already have fully functioning program, but I have no idea how to make it work with multiple users. I have tied to google for solution, but all I could find is how to create local database, not how to make it accessible by placing it in server computer.
Could you guys please help me? If you need more details, please let me know!
P.S. This is WPF application, .NET 4.5, created using Visual Studio 2012 Professional.
Thank you!
The error message pretty much sums up the problem: SQL Server Compact does not support opening database files on a network share.
SQL Server Compact (aka "local database") is to be consumed by a local application; even if it was a web app serving many requests, the application itself is local.
If you want to have multiple remote connections (i.e. centralized DB, distributed app), you should look at using an instance of SQL Server (any SKU would probably work, even SQL Server Express). Those will use MDF files instead of SDF files, so you might want to refer to Convert .sdf database to .mdf database. You'll probably also need to set up a user identity for your connection string, so check out this link on CREATE USER and Difference between a User and a Login in SQL Server to understand how that can be configured.

How can I convert a program currently using an Access database to use Microsoft SQL Server?

I have a Windows application written in C# that works with an Access database file.
Furthermore, I use some DataSets in my project that work with this Access database.
Arising from this, I have two questions:
How can I convert the Access database file into an SQL Server database, and
How can I convert the project code (using Access DataSets) to work with the SQL Server database?
I believe that MS-Access has an "export to SQL" functionality somewhere.
simple google reveals details here and here
Try SQL Server Migration Assistant for Access from the link below.
http://www.microsoft.com/downloads/details.aspx?FamilyID=d842f8b4-c914-4ac7-b2f3-d25fff4e24fb&displaylang=en
and for SQL Server Migration Assistant 2008 for Access
http://www.microsoft.com/downloads/details.aspx?FamilyID=133b59c2-c89c-4641-bebb-6d04476ec1ba&DisplayLang=en
you can import database from access db to sql server. for this you can make a new db in sql server, then press right click in db name, after that from showed menu, go like below:
Tasks->Import Data
use Microsoft Access as data source.
this is the best way.
Have you tried using the inbuilt upsizing wizard in MS Access? Under Access 2007 its under the Database Tools tab | SQL Server.
From the description: "The Upsizing wizard allows you to easily upsize your Microsoft Access Database to a Microsoft SQL server database"

Sql Server 2014 Express Edition database backup from c# - Sql Error

I am using Sql Server 2014 Express Edition. I am using Visual Studio 2015.
I have created a c# Winform app that uses a database. In the app, I have a button that is suppose to backup the database. On the button click event, the sql command
"backup database testdb to disk = #fullfilename";
is executed using sqlcommand and ExecuteNonQuery.
When I test this out, I get an error:
Failed to backup databaseSystem.Data.SqlClient.SqlException
(0x80131904) Operating system error 3(The system cannot find the path
specified).
I am testing the backup trying to get it to save to a mapped drive. I have looked on google and tried the approached recommended. I have change the login service for Sql Server to a domain user. I have mapped the drive using that same domain user's credentials. I have verified that the user has all permissions to the share,etc. No joy. Same problem.
Would love to hear some pointers on how to get this to work. Note: it works just fine if you use a local, non mapped drive.
Note: It must use mapped drives or UNC's. Its a requirement.
thanks.
Backup to UNC is supported and should work without problems.
My troubleshooting suggestions:
Use UNC instead of mapped drive and make sure the destination folder exists prior to starting the backup
Copy the SQL command into SSMS and manually start the backup
If backup via SSMS works and your app still fails, startup SQL Profiler and look at the SQL command your app sends
Good luck!

Categories

Resources