How to use Azure SQL database when internet is down? - c#

Let's say I have a C# WPF application connected with Azure SQL database, everything works fine and my queries work well. The only issue is when sometimes the internet is down, it cannot connect with the database and shows an error at the connection string (which is pretty obvious). Is there any way I can alter my connection string to connect with the database offline, at least be able to view the data, given when the internet is back, the updates are sent to the Azure portal as well (preferably automatic but manual will work). Through some research, I was able to get something as Sync my database with others option in the Azure portal. I was wondering if that's what I am looking for or is there any other alternative that you may suggest?
Thanks.

You can take advantage of Azure SQL Data Sync to sync even a local SQL Server Express database with your Azure SQL Database. Your Azure SQL Database will be configured as a "hub" database and the local SQL Server instance as "member database". You can configure automatic sync on/off and who wins (the hub or the member database) in case of conflicts). You need to configure the sync bi-directional so you can connect to Azure when Internet is available manipulate data and connect locally when there is no Internet connection. Once the Internet connection is restored the can be synced as you have configured it, manually or automatically. You will have to install an Agent on the local computer where SQL Server resides. For information about how to configure SQL Data Sync please visit this tutorial.
Take in consideration tables in your database should have a clustered index to be able to use SQL Data Sync.

Related

Two-Way Synchronization between Azure SQL and wpf/uwp clients

I have a Azure SQL database, and then clients (UWP and WPF) running SQLite that gets data from the database.
The clients can change the data and it updates the Azure SQL rows and they can insert new items/rows.
My problem is that multiple clients are working at the same time and i would like the client to update as soon as there is a change (insert/update/delete) on the Azure SQL database. Today the user has to press update in order to get latest.
However I not sure how to implement this.
I have been looking into using SQL "Change Tracking" https://learn.microsoft.com/en-us/sql/relational-databases/track-changes/about-change-tracking-sql-server?view=sql-server-2017and can easily active Change Tracking in Azure on the SQL server and Table, however i cannot find any documentation on how to use this to sync to client in C#, is there some?
Maybe there is a better way of doing this?
Any input is much appreciated.

How to auto sync local SQl Database with Microsoft Azure Sql database?

I have a ADO.net application which generates some data in regular intervals that is stored in a local SQL server. I want that database to sync with Microsoft azure SQL database automatically. What would be the best process to make it happen?
You have two options. One of them is SQL Data Sync which will sync you local database with an Azure SQL Database and viceversa. It is a bi-directional replication that works best with SQL Server 2008 R2 (and later) on-premises databases. This service is in preview and you can get started with it by visiting this documentation.
Your second option is Snapshot and one-way replication that works with SQL Server 2012 and later. You can get started with it on this documentation.
Hope this helps.

VS application can't connect to database after attaching it in SSMS

I have a windows form application (developed in VS Express 2013) that connects through an instance of SQL Server 2012 to a database. Both the application and database are on my local system; I just needed a GUI to more easily interface with this very large database that stores my research data. When I initially compile and deploy the application, it works fine and has no connection problems with the database. However, if I then attach the database in SQL Server Management Studio (which I sometimes want to do) I get an error the next time I try to use the application - "Cannot open database ..... requested by the login, the login failed". I get this error even if I take the database offline and detach it before quitting SSMS. And just to be clear - I'm not making any changes to the database in SSMS, I'm just looking at the data. The connection string used by VS is Data Source (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\CollectionMetricsDatabase.mdf;Integrated Security=True.
Any idea what the problem is?
Maybe the instance of SQL Server 2012 has a max number of concurrent connections and you exceed that with your two connections at once (SSMS connection and application's connection). Check the settings in SSMS.
Another thing to try - Based on your connection string, you are using Integrated Security, which in my experience means the application connects using Windows credentials. That can be fragile, because it means that whatever 'user' runs the application (if hosted in IIS, this will be the App Pool user) is the one whose Windows credentials are used. I would suggest creating a SQL login user (in SSMS) for the database, with db_owner access, and then changing the application's connection to be username/password based instead. You may need to enable Mixed Authentication for the SQL Server instance in SSMS if it doesn't already allow it.
You need to connect in SSMS with the localDB connection string. Attaching it will prevent it from working with localDB.
In SSMS, create a connection to (LocalDB)\v11.0. You should see your DB there already.
The problem is that you are connecting to the database file directly not through SQL Server.
Only one user can have a lock on the file at the time.
You need to recreate a connection string for your app.
That is why you were needing to detach the database.
Since this is only a personal project you could live with things as they are, at least you know the server is only running when you need it.
create connection msdn

Installing C# Windows Form Application with Database on another system

I have developed a winform application in C#.net and using SQL Server 2008.
My application inserts and updates values into database.
Is it possible to install the application on a another system which doesn't have sql server on it?
Imagine using sql azure. Cloud based sql server. The database is never on the same physically computer. It's all down to the connection string.
With an on premise database you need to make sure the database allows external connections, maybe opening up firewall etc. then make sure the connection string is set correctly on the application to talk to external database.
You can even configure to change the connection string as required pointing at different databases depending on the individual requirements.
Scott
Yes, you can. You can access the DB remotely by referring remote DB server in connection string.
It is possible, if you are looking to run the application on machine that is running on the same Domain as the SQL Server and has privileges to the SQL Server.

Share a SQL Server CE database in Azure Web and Worker roles

I'm trying to use a SQL Server CE database in Azure Web and Worker role and use it with EF. I have installed EntityFramework.SqlServerCompact (v4.3.6) and seems to work fine on the worker role. (which puts data in the database.)
Although when I try to read the data from my Web Role, it doesn't seem to recognize the database created by the worker role, and creates a new DB.
Database seems to be created by the worker role at \Debug\roles\WorkerRoleName\approot.
What is the best place to create the DB ? (Web role's App_Data ? or a blob storage location ?) and how do I configure EF so it looks in the same place no matter which role I ask the data from ?
If this is not possible with SQL Server CE, what other options do I have ? (don't want to use SQL Azure or table storage)
Thanks
I think you'll find SQL Server CE to not be viable for you, as it's a locally-installed database. I'm not sure if you've tested with multiple instances of your worker role, but you should find that these instances will not see each others' data (every instance is its own virtual machine). SQL Server CE is going to store its database file (the .sdf file?) in a local folder of the instance. Without some type of file-sharing set up, you won't be able to access this file from anywhere other than the instance it's installed on. And before you go exploring something like SMB, you should think about how SQL Server CE works, and if it would even support multiple database engines trying to read/write the same file.
I'm not sure why you want to avoid SQL Database (formerly known as SQL Azure), as it is db-as-a-service and may be accessed by all of your role instances, whether web or worker (or from anywhere else). Table Storage is something entirely different and not a SQL-based data store, so that makes sense.
One other option is to consider running SQL Server in a virtual machine, as SQL Server supports multiple clients just like SQL Database. There's a SQL Server image in the Virtual Machine gallery that you can use to spin up the database. You could then secure the connection from your cloud service to your SQL virtual machine either with a virtual network or an IP-ACL'd endpoint allowing only your cloud service's IP address to access it.

Categories

Resources