Quantcast
Channel: SQL Server Database Engine forum
Viewing all 12554 articles
Browse latest View live

Inserts only if not exists in the highly concurrent system.

$
0
0

Hello,

I have a pretty simple task: I need to insert a new row to a table only if the row does not exist yet. But I need to be sure that I will never get PK violation error in the highly concurrent system.

For example, if I have a table like this:

IF OBJECT_ID('dbo.TEST_TABLE', 'U') IS NOT NULL
	DROP TABLE dbo.TEST_TABLE;
GO
CREATE TABLE dbo.TEST_TABLE
(
	ID int NOT NULL,
	DATA varchar(128) NOT NULL,
	CONSTRAINT PK_TEST_TABLE PRIMARY KEY (ID)
)
GO

It is obviously a bad idea to use the following approach:

--EXEC dbo.USP_TEST_PROCEDURE @Id=1, @Data='Some data';
CREATE PROCEDURE dbo.USP_TEST_PROCEDURE
(
	@Id int,
	@Data varchar(128)
)
AS
BEGIN
	SET NOCOUNT ON;

	IF NOT EXISTS(SELECT 1 FROM dbo.TEST_TABLE WHERE ID = @Id)
	BEGIN
		INSERT INTO dbo.TEST_TABLE(ID, DATA)
		VALUES(@Id, @Data);
	END
END
GO

This is due to the fact that 2 users might run this SP with the same @Id at the same time and both will go insight IF statement if the row does not exist yet. This will result to PK violation error for the second user.

My question is: If I rewrite the SP the following way, will it be the reliable solution?

CREATE PROCEDURE dbo.USP_TEST_PROCEDURE
(
	@Id int,
	@Data varchar(128)
)
AS
BEGIN
	SET NOCOUNT ON;

	INSERT INTO dbo.TEST_TABLE(ID, DATA)
	SELECT @Id, @Data
	WHERE NOT EXISTS(SELECT 1 FROM dbo.TEST_TABLE WHERE ID = @Id);
END
GO

Thank you in advance.

 

Alexey


The Index Allocation Map (IAM) Page XXXX Is Pointed - Issue

$
0
0

Hi, 

New to SQL. Got given a database that had seen some corruption a while ago.. last known good back up is longer that 80 days ago so they don't want to restore back that far. 

DBCC check DB is showing this error. 

Msg 2575, Level 16, State 1, Line 1

The Index Allocation Map (IAM) page (34:25972) is pointed to by the next pointer of IAM page (0:0) in object ID 0, index ID -1, partition ID 0, alloc unit ID 72057600029753344 (type Unknown), but it was not detected in the scan.

CHECKDB found 1 allocation errors and 0 consistency errors not associated with any single object.

repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKDB


I could use a hand figuring out how to resolve this issue. 

BTW this is SQL 2008 R2 SP1



Trace flag 4199 on SQL Server 2014 causes a query to never completes

$
0
0

Hi all,

I've two identical instances (SQL Server 2014 Standard Edition 12.0.4459), on both instance it exists one database which is identical on both.

One these instances has TF 4199 enabled at startup, on this instance a given query (a complex one which involved XML search and some huge MERGE statements) never completes (i've killed the query after 10 minutes). I have no locking during this execution, CPU is very low and the request seems to be stuck on the MERGE statement that bounces from RUNNING-RUNNABLE state.

On the instance without TF4199 the query completes in 0.3 seconds on average. If I enable TF 4199 only for the current session and I run the query again (after having flushed the plan cache) the query again never completes, so I think TF 4199 is guilty.

Any advice how to drill down the problem?

how to measure effect of adding secondary FG to the database?

$
0
0

Hi there,

I recently added a secondary datafile and a new FileGroup to a database. I moved some of the heavily used indexes to this new FG. My question is  what ways can I check how this is affecting server performance? I compared wait stats, with single FG and with additional FG. Is waitstats good way to measure up performance in this case ? Should I check DiskIO for this ? 

Please let me know how do you measure up affecting of moving indexes to new FG. 

Thanks!

Occasional connectivity issues.

$
0
0

Greetings. We are getting SQL Server connectivity errors on a very intermittent basis. We've looked everywhere and all the info we have is posted below from the various sources. Note that this is not occurring from just one app server but a few, and that it's also occurring on more than one SQL Server instance.

Application Error (more details lower in the thread):

The connection error occurred again last night (log message):

System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake.

SQL Message Captured:

-         Interesting to note the high time to establish SSL in yellow

-         <value>Network error code 0x2746 occurred while establishing a connection; the connection has been closed. This may have been caused by client or server login timeout expiration.Time spent during login: total 12109 ms, enqueued 0 ms, network writes 1 ms, network reads 2109 ms,establishing SSL 9997 ms, network reads during SSL 9997 ms, network writes during SSL 0 ms, secure calls during SSL 0 ms, enqueued during SSL 0 ms, negotiating SSPI 0 ms, network reads during SSPI 0 ms, network writes during SSPI 0 ms, secure calls during SSPI 0 ms, enqueued during SSPI 0 ms, validating login 0 ms, including user-defined login processing 0 ms. [CLIENT: myIPAddress]</value>

Network Capture (trace file attached):

-         There are several retransmissions from the SQL instance to the App server (myAppServer (myIPAddress)

-         Then there is a reset request from the app server to the SQL instance

-         467         2016-07-19 08:27:00.405430160  10.7.50.10            10.7.4.125            TCP        68           44590 1433 [RST, ACK] Seq=1496031372 Ack=1496031636 Win=0 Len=0

-         Also see the below regarding SSL Self Signed Fallback.

...^......$....*....+....,....0....1.$..U......:............v,..M...K.?.....j...B..w.}./{........0...........%....&....'....'....(............[1496030773 bytes missing in capture file]...^......$....*....+....,....0....1.$..U......:............v,..M...K.?.....j...B..w.}./{.....[1496030819 bytes missing in capture file]...0...........%....&....'....'....(...............................W.......y`...3.....@..!.F...B0....*.<./.=.5...

.'.....+.#.,.$. .

.@.2.j.8.......G........

myDBServer.

...............

..................................m........`...Q..W......`.....N&. .~ot.U.zr3 .... B0....j.zO.'Q\..5..X..@q....gP...<.. ...................0...0..b...........T...Iu....0.0

. *.H..

.....0;1907..U...0.S.S.L._.S.e.l.f._.S.i.g.n.e.d._.F.a.l.l.b.a.c.k0..

160714073545Z.

460714073545Z0;1907..U...0.S.S.L._.S.e.l.f._.S.i.g.n.e.d._.F.a.l.l.b.a.c.k0..0

. *.H..

.........0.......R..H...4.....Jr.U.4rl'..?.N

.- .._k...-... q...j...[(.2'...Nc.4......WbTI..W..j.;..(+S/..U..P%..&..;.....#..Y....E....o{a.6..h5.....0

. *.H..

............/....;.u..8...... F].X..xP-.^\.H.[......@...G...lG:*......wJ...Eh......$....;.........s......f.,.n......PP#.G......->7.:............................1.XL..&....P...JM.....]D....v?N....`E{N..._?.9.OG....w..Ph.......!....5..e.m......Po.....G.../s...X..[..!]...g....*.8..K..+Y=.............P.w......"...........j...p.....,....U.. mol.D].w')..!..N.)........J2F.!.4.....C.....c..............Pf..|..

p..PC.f.7....

....~sGT...4f./.L..j...dp.....T.>............(....p......U.

All ideas are welcome, thanks!


Thanks in advance! ChrisRDBA


Cluster Node evict on Active Passive

$
0
0

Hello Experts

I have a weird question may not sounds good. But just want to clarify my doubt.

I have an Active-Passive 2 Node Cluster We have decided to remove once Cluster Node [ The Passive Node has been Removed]

Now all the Resources are Running on my Active Node. [Obviously it will be acting as single node Cluster]

Is there a any possibilities to remove the Node [Active  Node] from Cluster services and bring my SQL Instance into Standalone Instance with out removing the existing one.


Nag Pal MCTS/MCITP (SQL Server 2005/2008) :: Please Mark Answer/vote if it is helpful ::

Unable to connect to SQL database using a domain user

$
0
0
I'm able to login to SQL using SQL authentication but am unsuccessful with using Active Directory Password Authentication. I have gone on the Config Manager and added a domain user and password on the 'log on' section of the SQL Server Properties. When I try to login to SQL using the domain user, I get an error saying "A connection was successfully established with the server, but then an error occurred during the login process. The certificate chain was issued by an authority that is not trusted." How do I assign permissions to the domain user?

SMO causing deadlock

$
0
0

We have .Net code that does database replication using SMO. We use SMO to extract schema from source database and create them in destination database. And in recent past we started receiving bunch of deadlock issues. On analyzing the deadlocks graphs we found that some system base tables (ex: sys.sysrowsets) are causing the deadlocks. On some more investigation we found that..there are some SQL jobs running on parent DB that alter few tables (like renaming column, creating new column, dropping and recreating index etc.) that will internally update SQL Server base tables. At the same time using SMO we are capturing definition of tables which again depends upon system base tables internally. This is causing deadlock and SMO is the deadlock victim.

My question is

1. Is there is any setting available for SMO that will avoid deadlocks?

2. If not is there is any simple alternate way to extract schema of SQL objects?

For you reference I am pasting the error and deadlock graph here:

<StackTrace>   at Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithList(DependencyCollection depList, SqlSmoObject[] objects, Boolean discoveryRequired)

   at Microsoft.SqlServer.Management.Smo.Scripter.ScriptWithList(Urn[] urns, SqlSmoObject[] objects)

   at Microsoft.SqlServer.Management.Smo.Scripter.Script(Urn[] urns, SqlSmoObject[] objects)

   at DataMigration.BulkCopyTable(String schemaName, String tableName)  at DataMigration.CopyTableWithData()

</StackTrace>

<ExceptionSource>Microsoft.SqlServer.Smo</ExceptionSource><Data><HelpLink.ProdName>Microsoft SQL Server</HelpLink.ProdName><HelpLink.BaseHelpUrl>http://go.microsoft.com/fwlink</HelpLink.BaseHelpUrl><HelpLink.LinkId>20476</HelpLink.LinkId><HelpLink.ProdVer>11.0.2100.60 ((SQL11_RTM).120210-1917 )</HelpLink.ProdVer><HelpLink.EvtSrc>Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText</HelpLink.EvtSrc><HelpLink.EvtData1>Script</HelpLink.EvtData1><HelpLink.EvtData2>Server</HelpLink.EvtData2></Data><SqlException><Message>Transaction (Process ID 379) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.</Message>

 

 

 


openrowset - where is dsn gotten from

$
0
0

Hi we run 2012 enterprise. I ran ssms on my local, connected to a dev sql server and tried running an openrowset query

select * from openrowset ('xxx','DB2p';'yyy';'zzz','SELECT * FROM ...FETCH FIRST 1000 ROWS ONLY WITH UR;').

The error I got was...

--Msg 7403, Level 16, State 1, Line 1

--The OLE DB provider "xxx" has not been registered.

I have to look for the other bitness odbc dsn utility but under syswow64, do see this dsn (DB2P) when running odbcad32 on my local.  I cant verify that I guessed the provider name correctly because odbcad32 shows a driver name only, not provider.  But I did use a provider name I'd seen previously when installing a db2 client tool.

My OS is 64 bit.  I think my first question is where does sql pick up the dsn in this case?  From the dev sql server or from my local?

My access to various servers is limited. 

plumbing for openrowset usage

$
0
0
Hi we run 2012 enterprise. I'm contemplating use of openrowset to deal with a lookup from sql server to db2. From what i remember, a dsn would need to be created/stored on the sql server with various attributes (provider,userid etc) of the db2 connection.   But then it gets fuzzy for me.  Does that dsn then need to be represented in a sql server object or can the engine just use the dsn directly if an openrowset query is run?

Failure on Trigger update on a linked Server

$
0
0

Hello,

I know that problem has been discussed several times,but I don't find a solution.

We want to update stock information from our ERP (W2008R2 - SQL 2008) to our WebServer (W2008R2 / SQL 2005).  The Webserver is distant and only accessible through internet.  All the security between firewalls are done.

we have created on the Webserver a SQL user with the proper rights to acces the web DB.

On the ERP SQL server, we use sp_addlinkedserver and sp_addlinkedsrvlogin.

In sql studio manager on the ERP server, I am able to select * WebSrv.SiteDb.TheRightTable, then we create a Storedproc in order to make a full update on our items that runs on ERP server and update WebServer.

Then we have create a trigger in order to update in live the right item stock information. and we faced our first error : 

OLE DB provider "SQLNCLI10" for linked server "webserver" returned message

"The partner transaction manager has disabled its support for remote/network transactions.".

Msg 7391, Level 16, State 2, Line 1

The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "webserver" was unable to begin a distributed transaction.

Why DTC is interfering on triggers while, it doesn't in an interactive session ?

But we enabled DTC with Inbound and Outbound on both server, we test "Allow remote clients" on each and both servers

and we are still receiving that "no transaction is active"

You have to know that the webserver name has been added by it domain name www.mysite.com, but its netbios name is anything that is unknown, thus cannot be resolved on the ERP server.

what are we missing ?

Thank you for your time :)

yves

Extent (1:11930744) in database ID 6 is marked allocated in the GAM, but no SGAM or IAM has allocated it.

$
0
0

after reading http://msdn.microsoft.com/en-us/library/aa275767(v=sql.80).aspx, still have no idea except finding a primary support.

 The issue is: I run a dbcc checkdb noindex with physical_only(because now it is busy hours), I got this error below, not sure if it is hardware issue or not, how to determine it?

The bad thing is my clear backup is last week, not sure if restore from a full backup of now to a different disk will work?

Msg 8967, Level 16, State 216, Line 1

An internal error occurred in DBCC that prevented further processing. Contact Customer Support Services.

DBCC results for xxx.

Warning: NO_INDEX option of checkdb being used. Checks on non-system indexes will be skipped.

Msg 8921, Level 16, State 1, Line 1

Check terminated. A failure was detected while collecting facts. Possibly tempdb out of space or a system table is inconsistent. Check previous errors.

Msg 8905, Level 16, State 1, Line 1

Extent (1:11930744) in database ID 6 is marked allocated in the GAM, but no SGAM or IAM has allocated it.

CHECKDB found 1 allocation errors and 0 consistency errors not associated with any single object.

CHECKDB found 1 allocation errors and 0 consistency errors in database xxx.

Hey my online index rebuild caused a deadlock

$
0
0

We recently changed our twice-weekly index rebuilds to use the "online" feature, even though it takes twice as long we hoped it would eliminate some blocking we see.  And it did.  And it all seemed wonderful.

Until last night when it caused a couple of deadlocks with one of our batch processes.

The first time it was a pagelock and keylock and the index rebuild was the victim.

The second time it was an objectlock and hobtlock and our process was the victim (which is OK because it looks for deadlocks and does a retry).

But I thought the online rebuilds would NEVER do that, or hardly ever?  Or, ?

Thanks,

Josh

"Login failed for user" in SQL Server Management Studio

$
0
0

I'm trying to login to SQL using a domain account and am receiving this error "Login failed for user, Error Number: 18456, State: 1". I went on the SQL Server Config Manager and added a domain user and password on the 'log on' section of the SQL Server Properties. The domain username and password are correct but I'm still getting this error. In the connections properties, I checked the box "trust server certificate". Why isn't SQL letting me log in?

SQL 2012 A significant part of sql server process memory has been paged out issue

$
0
0

Hi there,

I have weird sql 2012 server memory issue. SQL server seems not using all free memories. 64bit sql 2012 on 64bit server 2008 r2 with 32gb memory. No using locked page on this server. Max server memory is set to 27gb. SQL working set is only use 7 gb whereas other servers are using 27gb. May i know if anyone can help me find the root cause of this problem? 

Ring buffer results

RmNotification PRODIndicatorsProcessIndicatorsSystemRmDateTimeTargetMemoryCommitedMemoryPagesMemoryMemoryUtilizationTotalPhysicalMemoryAvailablePhysicalMemoryTotalPageFileAvailablePageFileTotalVirtualAddressSpaceAvailableVirtualAddressSpace
RESOURCE_MEMPHYSICAL_LOW2002:05.317,018,27217,018,26015,570,4405233,553,97618,009,08067,106,10035,784,6248,589,934,4648,486,319,244

DBCC memory status results

Process/System Counts                    Value
---------------------------------------- --------------------
Available Physical Memory                19751993344
Available Virtual Memory                 8689990840320
Available Paging File                    38016155648
Working Set                              7485046784
Percent of Committed Memory in WS        47
Page Faults                              3606411729
System physical memory high              1
System physical memory low               0
Process physical memory low              0
Process virtual memory low               0

(10 row(s) affected)

Memory Manager                           KB
---------------------------------------- -----------
VM Reserved                              102838744
VM Committed                             15343948
Locked Pages Allocated                   0
Large Pages Allocated                    0
Emergency Memory                         1024
Emergency Memory In Use                  16
Target Committed                         27648000
Current Committed                        15343952
Pages Allocated                          13758576
Pages Reserved                           162832
Pages Free                               134352
Pages In Use                             14155048
Page Alloc Potential                     12110552
NUMA Growth Phase                        0
Last OOM Factor                          0
Last OS Error                            0

(16 row(s) affected)


What does a 1ms async_network_io mean?

$
0
0

Since we had one app feature that was having some issues in and around async_network_io waits I started fishing for them, and now I can see we get them sporadically, probably like a few an hour judging from my sample, mostly with wait times of 1ms or even 0ms indicated.

That's very minimal impact, but I'm just wondering, what does it mean?  Does everyone get those as just a network glitch?  Does it mean we have a number of different app features that are slow to consume data?

Thanks,

Josh

Some SQL jobs suddenly stop working, always "executing"

$
0
0
Hello, we have a had a few SQL jobs start executing but not finishing. Sometimes they fail after 30-40 hours, but usually we catch them and cancel them. The jobs are stored procedures that run in just a couple seconds if we just execute the SP. The jobs ran fine until a week or so ago, I don't know of any changes to the server. I do know if I run the job scheduled or manually start the job, it is always failing. If I just run the SP, it is always succeeding. Nothing appears in the error logs. The jobs say they are executing, but they never finish. I tried to force recompile on the SPs in case there was a parameter sniffing issue, but that didn't help. 

dbcc indexdefrag

$
0
0

Hi 

    We are using dbcc indexdefrag to defragment the indexes. We know that this is going to be deprecated in the coming releases. One question here specific to "dbcc indexdefrag". Whether "INDEXDEFRAG" will compact the LOB columns or not. 

Because we are facing the issue in one of the servers, after deleting huge data , the space is not released. We tried to shrink the database but no positive result. We are checking the fragmentation levels of huge tables, which are within the acceptable %, except for LOB columns.  These are the questions: 

1. dbcc indexdefrag will defragment the LOB columns or not 

2. dbcc indexdefrag  is it online operation ?

Thanks


-- Reddy Balaji C. ##Mark as answer if it solves the issue

SQLServer 2016 - "Maintenance clean up task" stuck - xp_delete_file problem

$
0
0

Hello,

On our new SQLServer 2016, the "Maintenance Cleanup Task" do not delete backup file.

I never had the problem with on older installation (2008R2 to 2014)

In the activity monitor, the session running this command is waiting on "MSQL_XP" .

 "EXECUTE master.dbo.xp_delete_file 0,N'U:\Backup\MSSQL13.SSDE\MSSQL\Backup\model\model_backup_2016_09_16_155708_9880904.bak'"

Then after 60 seconds, the task go in error : 

Executed as user: xxxx\yyyyy . Microsoft (R) SQL Server Execute Package Utility  Version 13.0.1601.5 for 64-bit  Copyright (C) 2016 Microsoft. All rights reserved.    Started:  16:08:16  Progress: 2016-09-16 16:08:16.77    Source: {F609BD64-CBC9-42CF-85EE-3537D0A1DF7A}      Executing query "DECLARE @Guid UNIQUEIDENTIFIER      EXECUTE msdb..sp...".: 100% complete  End Progress  Error: 2016-09-16 16:09:16.89     Code: 0xC002F210     Source: Maintenance Cleanup Task Execute SQL Task     Description: Executing the query "EXECUTE master.dbo.xp_delete_file 0,N'U:\Backup\MS..." failed with the following error: "Error executing xp_delete_file extended stored procedure: Specified file is not a SQL Server backup file.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.  End Error  DTExec: The package execution returned DTSER_FAILURE (1).  Started:  16:08:16  Finished: 16:09:17  Elapsed:  60.938 seconds.  The package execution failed.  The step failed.

I tried reading the header of this file, no problem found :

RESTORE HEADERONLY 
FROM DISK = N'U:\Backup\MSSQL13.SSDE\MSSQL\Backup\model\model_backup_2016_09_16_155708_9880904.bak' 
WITH NOUNLOAD;
GO

model_backup_2016_09_16_155708_9880904NULL1NULL012saSERVER\SSDEmodel8522003-04-08 09:13:36.0002833408340000001727000373400000017440000134000000172700037340000001665000372016-09-16 15:57:09.0002016-09-16 15:57:09.00000103319660913046081301708SERVER 512EBD0FE66-F91F-43F1-99C3-B52D803BB13690D16058-F1D1-4E96-8EC6-8D7BFDA42F15Latin1_General_CI_ASEBD0FE66-F91F-43F1-99C3-B52D803BB136000000000090D16058-F1D1-4E96-8EC6-8D7BFDA42F15NULLSIMPLENULLNULLDatabaseBC2B2591-4ECC-4760-8811-5E5D3EECCABD28334080NULLNULLNULL

I tried to delete a specific Maintenance plan text report, it worked fine. This problem seems to be specific for backup file, compressed or not.

I have the same problem on  every other server with SQLServer 2016.


Error Msg 2701 during SQL Server 2016 re-install

$
0
0
Did an uninstall of SQL Server 2016 (but seems like it left some issues behind). Now trying a re-install and am getting error msg 2701 stating a package {xxxx} is not available. Cannot find this package on my other two servers so am wondering what to do. Very little ends up getting installed. I really don't want to do another clean install of Windows 10, so would appreciate any advice

Mike

Viewing all 12554 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>