Concurrent users trying to insert and update in same SQL server table - sql-server

I have a scenario where 50-70 users are trying to do API calls to insert records in SQL Server tables and also update the existing records at the same time.
SQL server version is as below
Microsoft SQL Server 2017 (RTM-CU22) (KB4577467) - 14.0.3356.20 (X64) Aug 20 2020 22:33:27 Copyright (C) 2017 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2016 Datacenter 10.0 (Build 14393: )
(Hypervisor)
To avoid selects, AWS is doing READ REPLICA of audit tables to a new database.
However, INSERT + UPDATE on the same table (may be different records) are creating deadlocks.
How can this be handled in a seamless way ?
Generally this type of concurrent web application : how do they manage deadlocks? Should there by any queue mechanisms to set the order? If yes, how ?

Related

Hangfire on Windows Server 2019 with SQL Server 2019 Express

I'm trying to move to a new hosting provider and I'm having real difficulty getting my web site to run. It uses Hangfire on application startup to run some background jobs, whilst also serving web pages on the main thread.
The website seems to work for the very first page load and then subsequent accesses fail to run a reasonably complex Entity Framework search query.
Here's the server's configuration on the existing machine, via SQL Server's select ##version command:
Microsoft SQL Server 2017 (RTM-GDR) (KB4583456) - 14.0.2037.2 (X64) Nov 2 2020 19:19:59 Copyright (C) 2017 Microsoft Corporation Standard Edition (64-bit) on Windows Server 2016 Standard 10.0 <X64> (Build 14393: )
Shared operating system (not sure what this is)
SQL Server 2017 - Standard Edition
.NET Framework 4.8
Hangfire using SQL Server storage, with table's using the Hangfire schema
Other application tables, with tables using the dbo schema
Here's the server's configuration on the new machine, via SQL Server's select ##version command:
Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Express Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor)
Windows Server 2019
SQL Server 2019 - Express edition
.NET Framework 4.7,. (according to Plesk, although I've installed 4.8)
On the new server I have full RDP access, so can install whatever software I like on this machine. However, SQL Server Standard edition is extremely expensive for a little website like mine.
Is there something that is preventing the Entity Framework query running on the new Windows Server 2019 machine, with SQL Server Express? Does that combination not allow multiple schemas for the database, or is there some other restriction from this combination that I might not be aware of?
Running the website with SQL Server Express on my local Windows 10 machine runs fine.
I'd really appreciate any help with this, as I'm pulling what little hair I have left out of my head!
Thanks for trying to help, but in the end the problem was a lot simpler than I'd anticipated. I thought this was a permissions issue, but actually it's just a simple performance issue.
Running SQL Express on the new server failed because the machine didn't have enough RAM. It only had 4GB of RAM, and with Plesk and other software installed by the hosting provider, the free RAM was down to just a few hundred MBs.
Some simple queries that would take milliseconds to return on the old server could take over 2 minutes to return on the RAM limited new server.
Increasing the RAM to 8GBs fixed most of the issue, although using SQL Express is still significantly slower than the SQL Standard edition on the old server, and SQL Standard is alarmingly expensive to run just for this one website (the old server has a shared SQL Standard edition installation).

Finding delays when interacting with sql server database?

Lately, I've noticed delays in our sql server database when using the SQL Server management Studio GUI, when executing simple queries, and with web apps that interact with the DB.
For example, we have an asp.net application that uses this database. The web app and the sql server database are located in the same server. Lately, I've been seeing several The Wait operation timed out with different webforms in the page, and I know that the stored procedures invoked are not time-consuming. I don't want to increase the timeouts because I know it's not the stored procedures.
Another example: I use SQL Server management Studio. If I want to expand the Tables node, it takes an unusually long time to display all the tables. A few times I've gotten time out issues here.
Is there a way to see what the delays are? We have sufficient memory in the server and I've restarted the sql server installation and the server.
Our installation: Microsoft SQL Server 2016 (SP2-CU17) (KB5001092) - 13.0.5888.11 (X64) Mar 19 2021 19:41:38 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows Server 2019 Standard 10.0 (Build 17763: )

SQL2016 Not able to create Column Master Key

I just installed SQL 2016 Standard Edition because I wanted to use the 'Always Encrypted' feature.
However, when I tried to created a Column Master Key under Security->Always Encrypted Keys->Column Master Key, I got the following error:
productversion: 13.0.160.5, productlevel:RTM, edition:Standard Edition 64bit
Any ideas? Thanks!
I was having the same issue. I fixed it by updating to Sql Server 2016 SP1 from Sql Server 2016.
Previously ##version was:
Microsoft SQL Server 2016 (RTM-GDR) (KB3194716) - 13.0.1722.0 (X64) Sep 26 2016 13:17:23 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows 10 Pro 6.3 (Build 14393: )
Now ##version is:
Microsoft SQL Server 2016 (SP1) (KB3182545) - 13.0.4001.0 (X64) Oct 28 2016 18:17:30 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows 10 Pro 6.3 (Build 14393: )
Note also that my SSMS is totally up to date.
Tools > Check for Updates > Details - 13.0.16100.1
A coworker has a slightly older build of SSMS and does not even see the option to encrypt columns.
The issue was probably caused by restoring a SQL2014 database. I backed up a 2014 database and then restored it in 2016. SQL may have seen it as a 2014 schema and therefore complained Column Master Key not supported.
How I resolved it: In SSMS 2016, generate .sql script for the imported database (in Advanced settings, choose SQL 2016 script)
Install a new SQL 2016 instance (which may not be necessary will test) and run the .sql generated, rather than the restore option
"Always Encrypted is available in SQL Server 2016 (13.x) and SQL Database. (Prior to SQL Server 2016 (13.x) SP1, Always Encrypted was limited to the Enterprise Edition.)"
Source: https://learn.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-database-engine?view=sql-server-2017

Can't create column store index on SQL Server 2012

Got this error when trying to create a column store index on a fact table:
Msg 35315, Level 16, State 1, Line 1
CREATE INDEX statement failed because a columnstore index cannot be created in this edition of SQL Server. See Books Online for more details on feature support in different SQL Server editions.
This is from select ##VERSION
Microsoft SQL Server 2012 (SP1) - 11.0.3381.0 (X64)
Aug 23 2013 20:08:13
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
SQL Server Standard edition doesn't support columnstore indexes. From the version comparison for SQL Server 2012, you need Enterprise edition.
Although SQL Server 2012 is specified here, it's worth noting that SQL Server 2016 with Service Pack 1 now allows columnstore indexes to be created across all editions. See here for further details.

Cannot restore CDC-enabled DB on Express Edition

While restoring database I got this error
SQL Server cannot load database 'XXX' because Change Data Capture is enabled. The currently installed edition of SQL Server does not support Change Data Capture. Either disable Change Data Capture in the database by using a supported edition of SQL Server, or upgrade the instance to one that supports Change Data Capture.
Mine SQL Server
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (Intel X86) Jun 28 2012 08:42:37 Copyright (c) Microsoft Corporation Express Edition with Advanced Services on Windows NT 6.1 (Build 7600: )
I know there is no feature of CDC in Express Edition but i got XXX.bak file which i need to restore on my sql server. Is there any way of script to remove CDC feature from the file?

Resources