Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0

If you have a TRY/CATCH block then the likely cause is that you are catching a transaction abort exception and continue. In the CATCH block you must always check the XACT_STATE() and handle appropriate aborted and uncommitable (doomed) transactions. If your caller starts a transaction and the calee hits, say, a deadlock (which aborted the … Read more

Date time conversion from timezone to timezone in sql server

Unix timestamps are integer number of seconds since Jan 1st 1970 UTC. Assuming you mean you have an integer column in your database with this number, then the time zone of your database server is irrelevant. First convert the timestamp to a datetime type: SELECT DATEADD(second, yourTimeStamp, ‘1970-01-01’) This will be the UTC datetime that … Read more

SQL Server Connection Strings – dot(“.”) or “(local)” or “(localdb)”

. and (local) and YourMachineName are all equivalent, referring to your own machine. (LocalDB)\instance is SQL Server 2012 Express only. The other parts are depending on how you install – if you install with an instance name – then you need to spell that instance name out (SQL Server Express by default uses the SQLEXPRESS … Read more

What is the connection string for localdb for version 11

Requires .NET framework 4 updated to at least 4.0.2. If you have 4.0.2, then you should have HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v4.0.30319\SKUs.NETFramework,Version=v4.0.2 If you have installed latest VS 2012 chances are that you already have 4.0.2. Just verify first. Next you need to have an instance of LocalDb. By default you have an instance whose name is a single … Read more

XML Server XML performance optimization

I can give you one answer and one guess: First I use a declared table variable to mock up your scenario: DECLARE @tbl TABLE(s NVARCHAR(MAX)); INSERT INTO @tbl VALUES (N'<root> <SomeElement>This is first text of element1 <InnerElement>This is text of inner element1</InnerElement> This is second text of element1 </SomeElement> <SomeElement>This is first text of element2 … Read more

STRING_SPLIT in SQL Server 2012

Other approach is too use XML Method with CROSS APPLY to split your Comma Separated Data : SELECT Split.a.value(‘.’, ‘NVARCHAR(MAX)’) DATA FROM ( SELECT CAST(‘<X>’+REPLACE(@ID, ‘,’, ‘</X><X>’)+'</X>’ AS XML) AS String ) AS A CROSS APPLY String.nodes(‘/X’) AS Split(a); Result : DATA 1 2 3 4 5 6 7 8 9 10 11 12 13 … Read more