r/SQLServer • • Nov 30 '25

Question Deadlock avoidance techniques?

10 Upvotes

Long story short, we have a stored proc that does an UPDATE on a specific table. Our job scheduler can be running numerous instances of this proc at the same time. We are seeing deadlocks occur because these UPDATEs are causing page level locks on the table being updated and of course numerous instances are each acquiring page locks needed by the other instances. Eventually (hours later) SQL server choses one to kill which frees the deadlock. Ok in the sense that we can just rerun the killed instance, but really bad because each job needs to rerun every few minutes, so holding things up for hours causes huge issues for us.

In our proc, would using sp_getapplock prior to executing the UPDATE and then using sp_releaseapplock right after the UPDATE completes be a good way to mitigate the issue we are seeing? Something like the below, but we might make several attempts to obtain the lock a few seconds apart before giving up and calling RAISERROR.

DECLARE u/result INT;

EXEC u/result = sp_getapplock

u/Resource = 'MySemaphore',

u/LockMode = 'Exclusive',

u/LockOwner = 'Session',

u/LockTimeout = 1000; -- ms

IF u/result < 0

RAISERROR('Failed to acquire semaphore', 16, 1);

ELSE
BEGIN

<our UPDATE>

END

EXEC sp_releaseapplock u/Resource = 'MySemaphore', u/LockOwner = 'Session';

My main concern here is that if, for any reason, an instance of the proc fails to call sp_releaseapplock we'd be in worse shape than we are currently, because now (I think) we need to get a DBA involved to go and manually clear out the lock that was created, while all instances of the proc that get run in the meantime fail to acquire the lock and so do not do this UPDATE. Is there some way to guarantee that sp_releaseapplock will be called no matter what?

Are there any other approaches to avoiding these deadlocks that might be better?


r/SQLServer • • Nov 29 '25

Question Authentication=ActiveDirectoryMsi Container Apps SQL Connection

Thumbnail reddit.com
2 Upvotes

r/SQLServer • • Nov 28 '25

Question Sql reuse vps

6 Upvotes

I have an application where I need to use SQL Server, and I was thinking of buying a reuse license to install on a Linux VPS at NetCup. Has anyone had any problems doing this?


r/SQLServer • • Nov 28 '25

Question SQL server Express to production, is there any difference?

6 Upvotes

I might migrate later on when i learn the free version, if i want to upgrade will it be straight forward ? i think i need only to pay for license and i am good to go right? currently the express version with the 10gb limit is generous to be fair but was thinking for long term


r/SQLServer • • Nov 28 '25

Question How to Store The Result of Parameterized Query within a Scalar Variable?

6 Upvotes

I'm trying to prototype some functions to later use with my PHP web server, so I want to be able to send one variable back to the web server. Previously, I was executing the function on the web server by sending multiple queries to the DB, but I feel that has major performance losses.

Highly simplified version of the function. The end result is to have '@Count' return to the web server with the number of documents that exist in each Document column

While @i < 6
begin
set @Document = 'Document' + cast(@i as char(1));

set @query = 'select count('+@Document+') as DocCount from mydb.Documents where
'+ @Document +' is not null;';

-- ideally do something like @count = @count + (result of query)

set @i = @i + 1;
end;

r/SQLServer • • Nov 26 '25

Question How to migrate SSRS correctly?

10 Upvotes

Is there a way to migrate all SSRS objects (folders, reports, data sources, etc.) to a new server? Ideally, I’d like users not to have to re-enter credentials for data sources that use stored credentials after the migration. Is this even possible?


r/SQLServer • • Nov 25 '25

Discussion Ever since upgrading the database to SQL Server 2025, queries have been running noticeably slower.

27 Upvotes

After upgrading my SQL Server from versions 2014 and 2022 to 2025, I noticed a significant slowdown in query performance. This only happens when using SQL Server Authentication, but if I add Trusted_Connection=True, the queries run at normal speed; without it, they become very slow.


r/SQLServer • • Nov 25 '25

Discussion SQL Server rodando no GCP

Thumbnail reddit.com
1 Upvotes

r/SQLServer • • Nov 25 '25

Community Share SQL2025 Express Edition 50GB per database

28 Upvotes

Hi there, Just reading about SQL Server 2025 Express. The size limitations are way better than in the past – 50 GB per database instead of 10 GB. The other limitations are similar to the older versions.


r/SQLServer • • Nov 24 '25

Community Share Announcing optimized locking v2

22 Upvotes

Optimized locking is an attractive new feature in SQL Server 2025. But it isn't quite the same feature we added in Azure SQL in 2023 - it's better. Recent improvements reduce the overhead of locks even more.

Are locks always required to guarantee the ACID properties of a transaction? The answer might surprise you. Read the blog to learn more and let us know what you think: https://aka.ms/olv2.


r/SQLServer • • Nov 25 '25

Question Transactional Replication with AGs

0 Upvotes

We have a requirement to have some data sent from A to B, outside of the existing AGs.

What are the nuances when both the Publishers and Subscribers are in (different) AGs? Is it just a case of essentially manually duplicating on each node: so configure Publisher twice and Subscriber twice.

This is for a Reporting use-case when budgets simply don't allow for a third node in an Enterprise Edition AG: the Publishers are Ent and Subscribers are Std.

Thanks


r/SQLServer • • Nov 25 '25

Discussion SQL Server 2025 slow in SSMS?

10 Upvotes

I spun up a VM to test out SQL Server 2025, and installed SSMS 22 as well. First off, I notice right away that it takes forever to expand tables in the SSMS UI. I also connect via SSMS 18 and I see the same issue. Not seeing any potential fixes yet, but did see some discussion about it in the SQL Developer forums. This is frustrating...


r/SQLServer • • Nov 25 '25

Community Request Should RCSI be on by default?

5 Upvotes

Should RCSI be on by default for new databases in SQL Server and Azure SQL MI?


r/SQLServer • • Nov 24 '25

Question Managed instance real time backup options

2 Upvotes

We have a 'data' team who previously had a SQL server, part of their workflow was managing their own backups before they'd attempt to do anything with the data.

Like they might ingest data from a ftp, do a backup and then start to manipulate the data, being able to restore the backup when needed.

They are now on a managed instance, and it looks like these kind of manual backups are not possible for some reason, even through SSMS.

There are built in backups in Azure but it looks like the policies are per db and not per instance, which complicates things since they will occasionally just spin up a db for a temporary project and need a backup, so it's not feasible to go in and configure a policy every single time a database is created.

What are our options for this sort of thing? Would we need some third party service?


r/SQLServer • • Nov 22 '25

Community Share Announcing General Availability of the Microsoft Python Driver for SQL (mssql-python)

43 Upvotes

Super excited to share that the Microsoft Python driver for SQL is Generally Available!

Read more about it here: aka.ms/mssql-python-ga


r/SQLServer • • Nov 22 '25

Question Time to break Always On availability groups synchronize

5 Upvotes

I have two SQL Server 2019 instances with Always On availability group asynchronous mode. Let's suppose, there is failure on one node and connections between primary and secondary replicas break. What is time, when these two replicas can't connect again and we need restore backup to establish synchronize again? I can't find any information about this, maybe it depends on the specific number of transactions, the number of log backups or something else? Maybe I can monitor this somehow?


r/SQLServer • • Nov 21 '25

Community Request SSMS Friday Feedback...on any topic

19 Upvotes

This week's Friday Feedback is coming to you from Seattle, where I'm at the end of the PASS Data Community Summit. It's been a great week, and I've been talking to lots of users of SSMS, and GitHub Copilot in SSMS. I've heard all kinds of feedback over the past two days, which is why I don't have a specific topic today. I'm really interested in any feedback you have about either SSMS, or GHCP in SSMS, that you haven't been able to provide in previous feedback posts, or in person.

What do you want us to know?

Also, I still have a few SSMS 22 friendship bracelets left, if there are any SSMS #SQLSwifties here!


r/SQLServer • • Nov 21 '25

Question update/delete rules

2 Upvotes

I've tried adding update and delete rules to my university project database; however, they aren't working. I've tried changing the type of rule, but none of them seem to affect the relationship. Has this happened to anyone before, and how did you fix it?


r/SQLServer • • Nov 21 '25

Question Struggling with AI/ML and Python installation on MSSQL2025 GA

8 Upvotes

I swear that i did not have any issues installing AI/ML on CTP2.1, don't believe i tried it on RC0 or RC1, but gosh is installing python, R difficult on GA!

Can Microsoft or some good soul please share exact steps on installing AI/ML on 2025GA w/ Python 3.10 and also please share all of the exact versions needed and the icals (permission setups), Also I'm confused with this virtual account vs domain account setups. Aslo can i use Python 3.13 or 3.14 ? or is that not supported ?

Does any one have the exact steps on Windows 11 Pro for a SQL Server 2025 Enterprise Development environment ?

I see this article but its so confusing : https://learn.microsoft.com/en-us/sql/machine-learning/install/sql-machine-learning-services-windows-install-sql-2022?view=sql-server-ver17&viewFallbackFrom=sql-server-ver15


r/SQLServer • • Nov 21 '25

Question SSMS 22 Find and Replace Window Size

3 Upvotes

Greetings. I just started using SSMS 22. The find and replace window is tiny and its size cannot be modified by any means I have been able to learn. Can anyone point me in the right direction? It is super hard to use.


r/SQLServer • • Nov 21 '25

Question Calcul SSRS amont vs aval

0 Upvotes

Salut a tous.

Je suis en pleine construction des rapports SSRS (et débutant dessus) et les rapports sont assez conséquents (en moyenne 100 colonnes) alors l'optimisation n'est pas une option.

Ma question est : Lorsque je construit ma requete, est il intéressant de laisser SSRS faire quelque calcul ou alors ca va ralentir l'expérience utilisateur?

Je m'explique. Sur les 100 colonnes, 20 sont des colonnes "bruit" et le reste sont des colonnes "calculées", alors je me demandais ca vallait le coup d'imprter seuulement les 20 colonnes brut et de faire les reste via sur CALCUL SSRS...

mais je ne sais pas si SSRS est vraiment fait pr supporter du calcul en aval (Somme, division etc...) J'espère que j'ai été clair lol, merci !


r/SQLServer • • Nov 20 '25

Question Azure VM fails.

0 Upvotes

Hello. I've tried to deploy my first VM / SQL Server in Azure and keep encountering this, regardless of which which Windows and SQL version I use.

Note that Im using a free student account.

Any ideas on this?

{

"code": "DeploymentFailed",

"target": "/subscriptions/mysubid/resourceGroups/myrg/providers/Microsoft.Resources/deployments/CreateVm-microsoftsqlserver.sql2019-ws2019-sqldev-20251120135342",

"message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.",

"details": [

{

"code": "ResourceDeploymentFailure",

"target": "/subscriptions/344109e7-563a-4cd4-921e-6687c7f96e10/resourceGroups/myrg/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/VM1",

"message": "The resource write operation failed to complete successfully, because it reached terminal provisioning state 'Failed'."

}

]

}


r/SQLServer • • Nov 20 '25

Question Stored Proc - SSMS vs C#/EF

2 Upvotes

Disclaimer - yes, I know this is asked all the time. I've run down all the various resolutions without success. Looking for additional suggestions

For the time being, let's ignore whether or not this is the best way to do it, I'm much more curious about the 'why it's different' portion

There is a stored proc, relatively simple - takes a single parameter, varchar(max), which will contain a comma separated list

I've cleared the cache to ensure no old plans exist

SQL 2022 Standard

Running this proc from SSMS on my laptop, it takes 1-2 seconds. Running this same proc via C#, with the exact same parameter value, takes ~30 seconds.

Using the post here - https://sqlperformance.com/2014/11/t-sql-queries/multiple-plans-identical-query , I have confirmed that both execution sources end up using the same query plan, with the same SET options.

The code being used to execute the proc is below (from a dev). One other thing that's coming up somewhat odd - when looking at the rowcount values in Query Store, the C# execution is 20 rows more than the SSMS (that might be expected, I just don't know).

Any help would be appreciated, not sure where to go.

public IList<T> ExecuteUnmappedStoredProcedureWithReturnList<T>(string procName, SqlParameter[] parameters) where T : class, new()
{
// Static dictionary to cache properties of types
using (var connection = Context.Database.GetDbConnection())
{
if (connection.State != ConnectionState.Open)
connection.Open();

 

// ORIGINAL

 

using (var command = connection.CreateCommand())
{
command.CommandText = procName;
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = DEFAULT_SQL_COMMAND_TIMEOUT;

 

if (parameters != null)
{
command.Parameters.AddRange(parameters);
}

 

var resultList = new List<T>();

 

// Retrieve or add properties of type T to the cache
var properties = UnmappedStoredProcPropertyCache.GetOrAdd(typeof(T), type => type.GetProperties(BindingFlags.Public | BindingFlags.Instance));

 

var startTime = DateTime.Now;
var endTime = DateTime.Now;

 

using (var result = command.ExecuteReader())
{
startTime = DateTime.Now;

 

while (result.Read())
{
var entity = new T();

 

foreach (var property in properties)
{
if (!result.IsDBNull(result.GetOrdinal(property.Name)))
{
property.SetValue(entity, result.GetValue(result.GetOrdinal(property.Name)));
}
}

 

resultList.Add(entity);
}
endTime = DateTime.Now;

 

_Logger.Info($"[Timing] ExecuteUnmappedStoredProcedureWithReturnList.{procName} SQL Exeuction Time (Elapsed: {(endTime - startTime).TotalMilliseconds} ms) COUNT: {resultList.Count}");
}

 

return resultList;
}

 

 

}
}


r/SQLServer • • Nov 19 '25

Community Share Generally Available: Azure SQL Managed Instance Next-gen General Purpose | Microsoft Community Hub

Thumbnail
techcommunity.microsoft.com
17 Upvotes