With Windows SQL Server there are 3 user access mode settings per DB.
Multi_User
Single_User
Restricted_User
My question is, when exactly do you put a database in the "Single_User" of the "Restricted_User" mode?
For example, if you want to update the SQL Server and thus prevent further sessions from being established for the duration of the update?
Typical Restricted_User and Single_User are used when doing maintenance that needs to be done when the applications are offline but you still need to access the data or schema.
Examples
Data migrations that are spanning multiple hours/days accessing multiple tables /databases/files are often done when the system is offline to minimize locking/blocking.
Hardware migrations: Typically when moving to new hardware the database is also but in restricted mode before the service is turned off, to make some full backups, put the database offline, ...
Recovery: When your database is corrupted an you are restoring logs and performing ddbc checkdb (Although this is mostly done on a separate environment)
...
So basically when the DBAs/Developers wants to make sure nobody else can access the database but they still needs to be able to perform tasks.
In the enterprise environment this is often a fail-safe, as access to the database will probably be limited by firewalls, user policies when doing one of these tasks.
Patching SQL server or the OS is done when the service is stopped, as often OS patches require reboots and SQL Server patches require service restarts. When running in a clustered environment, it's done 1 node at the time, to maintain up-time. So restricted access is not used in these cases as the SQL Server is offline.
Related
I want a solution that match the below scenario:
We have 2 databases with 1 being the main DB and the other being the secondary DB. I want a process (executable, powershell, anything...) that can update the changes that I make in Stored Procedures in the main DB. the main DB is the database that we will make the changes then I want a process that update (simple delete and create) the older SP in the secondary DB.
How I can make this possible in the most simply way? If you will say software to work with please take in account that I only want freeware.
It seemed like you are defining something called Mirroring if I didn't assume wrong.
Database mirroring maintains two copies of a single database that must reside on different server instances of SQL Server Database Engine. Typically, these server instances reside on computers in different locations. Starting database mirroring on a database, initiates a relationship, known as a database mirroring session, between these server instances.
One server instance serves the database to clients (the principal server). The other instance acts as a hot or warm standby server (the mirror server), depending on the configuration and state of the mirroring session. When a database mirroring session is synchronized, database mirroring provides a hot standby server that supports rapid failover without a loss of data from committed transactions. When the session is not synchronized, the mirror server is typically available as a warm standby server (with possible data loss).
https://learn.microsoft.com/en-us/sql/database-engine/database-mirroring/database-mirroring-sql-server?view=sql-server-2017
Hope it helps
I have a calendar-type WPF program that is used to assign the workload to a team. The events are stored in an Access database and the program is accessed by one person at a time by remotely connection to a computer. The team has grown and multiple people would need to access the program simultaneously. I can install the program on several computers, but where should I move the database? On a software like Dropbox/Onedrive, on a SQL online host? Thanks.
You can use a SQL Server on many Cloud platforms (though I am not sure Dropbox can host SQL Server natively). Azure (Microsoft cloud) is a very mature solution. You still should verify, now that multiple users will be managing data, that the database is backed up a regular basis and that any updates to data should be done within transactions that your code should be aware of. 'Aware of' means that if there is a conflict your code should either resubmit or notify the user that the insert/update/delete failed.
I have an installation which has two SCADA (Intouch) HMIs and I want to save the data in an SQL Server database which will be in another computer. To be as sure as possible that I have an operating database I'm going to set a SQL Server mirroring. So I will have 2 SQL server databases with a distributor. About this I don't have any doubt. To make it easy to understand I've made an image with the architecture of the system.
Architecture.
My doubt is how do I configure the Alarm DB Logger to make it point, automatically, to the secondary database in case that the principal database is down for any unknown failover.
PS: I don't know if it's even possible.
Configure it the database in Automatic failover. The connection are handled automatically in case of a failover. Read on Mirroring EndPoints
The below Links should have more than enough information.
https://learn.microsoft.com/en-us/sql/database-engine/database-mirroring/role-switching-during-a-database-mirroring-session-sql-server
https://learn.microsoft.com/en-us/sql/database-engine/database-mirroring/the-database-mirroring-endpoint-sql-server
The AlarmDBLogger reads its configuration from the registry, so you could try the following:
Stop AlarmLogger
Change ServerName in registry [HKLM].[Software].[Wonderware].[AlarmLogger].[SQLServer]
Start AlarmLogger
But what about the two InTouch-nodes? What if one of those fails? You would have to make sure one of them logs alarms, and that they don't log duplicates!
The standard controls and activex for alarms use a specific view in the alarm database. You cannot change that behaviour, but you can script a server change in InTouch or System Platform.
Keep in mind that redundancy needs to be tested, and should only be implemented if 100% uptime is necessary. In many cases you will be creating new problems to solve instead of solving an actual problem.
Our application uses multiple databases and these databases can be created by user through UI. Basically these databases are created after loading data from data files (ETL process)
We delete these databases when they are not required.
We use following statement to delete it -
ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; Drop Database [{0}]
Recently we started facing an issue where the database goes into Single User Mode but DB is not deleted and application stops working because only one connection can be active at a time in this mode. This issue occurs very rarely and not consistent at all.
We don't have any clue on what is happening here.
If anybody has faced such an issues or what might be possible cause, please let me know.
We are using Sql Server 2008 R2
Regards,
Varun
You're probably running into a race condition. Between the time the database is set to single user and the time the DROP DATABASE command is issued if any other connection is successful then you will be unable to drop the database. In a high volume situation this can be difficult to resolve.
The best bet is to set the database offline instead of putting it into SINGLE_USER. Of course, in that case, you'll have to manually delete the database files.
I work with a particularly large environment where there are at any given time 50+ machines which are hammering the database for connections. Even with delays set between connections the number of attempts being made is extremely large.
In our case, we handled this race condition by disabling the service account which was attempting to access the database before performing the single-user and drop commands which eliminated the issue for us.
If your system features a similar common service account, you may be able to implement something similar.
The Set a Database to Single-user Mode documentation says:
Prerequisites
Before you set the database to SINGLE_USER, verify that the
AUTO_UPDATE_STATISTICS_ASYNC option is set to OFF. When this option is
set to ON, the background thread that is used to update statistics
takes a connection against the database, and you will be unable to
access the database in single-user mode
Otherwise, the connection that sets the database to SINGLE_USER is supposed to immediately become the current and single user of that database, until you close that connection (notice that it can remain "in use", if your system is making use of connection pools that hold the connection open, but that should be unrelated to your problem).
i have a security application that stores its data in a access database.now i'm required to
make a realtime synchronization (replication) between that access database and a new database in sql server 2005. these two database are the same.
any suggestion?!
i don't know how to do it using a windows service or not. i need exact technical answer.
Mostly, I would suggest you use a windows service to periodically check the MS Access db, and attempt to synchronize it with the Sql database.
This will allow you to remove the Human factor, and have this task run periodically to sync the dbs.
Have a look at
Creating a Basic Windows Service in
C#
Creating a Windows Service in C#
Also
Connect to Microsoft Access .mdb
database using C#
Beginners guide to accessing SQL
Server through C#
SQL server has built-in replication functionality that you get for free, so you don't need to worry about copying rows & tracking changes. There are several types of SQL replication that are used for different situations, such as merge replication, snapshot replication, and transactional replication. This last one, transactional replication sounds like what you want. Merge replication is used when you have users that might disconnect, go away and return later to synchronize (like remote users). Transactional replication is used where the subscribers and publisher are reliably connected. Snapshot replication generates a new snapshot each time synchronization occurs, and doesn't think about changes to the data. Read the MSDN documentation and find which of these types is appropriate for your situation.
Using these replication methods will require that you set up your tables in a SQL server or express instance - you can use that to synchronize with your SQL server and keep everything else Access as the front end. I think you want to follow astander's suggestion and use a windows service to trigger synchronization. However you can set up the Windows Synchronization Manager to automatically try to synchronize at startup, shutdown, when the computer is idle, etc. If you need finer control over triggering the synchronization then perhapse use a Windows app or service as astander suggested.