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

failed: run sql server agent job to call store procedure on another server

$
0
0

Sql server A, Sql server B, oracle database server  C

Now,

SQL server B load data from oracle database server C to sql server B's database BB, using store procedure Load_oracle

On SQL server A,

I create link server to connect SQL server B. Then run following T-sql to load from oracle database server C to sql server B's database BB

I use following t-sql on sql server A

DECLARE @RunStoredProcSQL VARCHAR(1000);
SET @RunStoredProcSQL = 'EXEC [B].[dbo].[Load_oracle]';
EXEC (@RunStoredProcSQL) AT [B];

It is successful. Takes 5 minutes to complete store procedure Load_oracle running on sql server B.I execute sql server query window under SSMS: paste those coding and execute

However, after I createed a job under sql server agent on server A, here is screenshot. 



I ran the job on Server A

I get failure message:

Executed as user: domain\user. Cannot create an instance of OLE DB provider "OraOLEDB.Oracle" for linked server "xxxx"(oracle server name). [SQLSTATE 42000] (Error 7302).  The step failed.

I checked providers under linked server: no OraOlEDB.oracle .

What's the problem? and how to fix it? It is successful under sql server query windows under sql server management studio?-- I past the code and run. But fail when I run these code though sql server agent job. Why?




Intermittent Connectivity Issues

$
0
0

Application team is facing intermittent connectivity issues to the database, they are facing below error, after multiple tries they are able to connect to the database.

Databases servers are configured with 3 node AlwaysON.

Application Servers are on Azure. 

Could anyone help what could be the issue ?

Error:

System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): Access is denied     


SQL Server Connection Issue

$
0
0

Microsoft SQL: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)

Getting above error intermittently with some prod DB servers (2016) while connecting from SSMS.

change datatype varchar to nvarchar in publication table (transaction Replication)

$
0
0

there is article published from serverA to serverB   (transaction Replication)

Table: product

datatype: varchar(50)

when am going to alter the table ,

alter table product alter column name nvarchar(50)

getting below error, & replication fails.

Msg 5074, Level 16, State 1, Line 32

The object 'v_fti_product' is dependent on column 'name'.

Msg 5074, Level 16, State 1, Line 32

The index 'is_product_site_id_vendor_id_includes__1' is dependent on column 'name'.

Msg 5074, Level 16, State 1, Line 32

The index 'IX_product_man__1' is dependent on column 'name'.

Msg 5074, Level 16, State 1, Line 32

The index 'IX_product_man___1' is dependent on column 'name'.

Msg 5074, Level 16, State 1, Line 32

The index 'NUNCLIX__56984' is dependent on column 'name'.

Msg 5074, Level 16, State 1, Line 32

The index 'ncls_Product_vendorid_incl_id_name' is dependent on column 'name'.

Msg 4922, Level 16, State 9, Line 32

ALTER TABLE ALTER COLUMN name failed because one or more objects access this column


PolyBase : Access Data in cosmodb using mongodb fails with error

$
0
0

Hi All,

I am trying to access data in my azure cosmosdb  using SQL Server PolyBase (cosmosdb was created using "Azure Cosmos DB for MongoDB API) 

I am able to connect and access documents using mongo shell. However when trying to create external table, getting below error.

Searched  though PolyBase logs and could not find any useful information which can help troubleshoot the issue.

Hence posting it here.

SQL Server version : Microsoft SQL Server 2019 (RTM-CU4) (KB4548597) 

CREATE DATABASE SCOPED CREDENTIAL azure_cosmos_db_cred_using_mongodb_connect_string

WITH IDENTITY = 'username', 
Secret = 'Key';

CREATE EXTERNAL DATA SOURCE AZ_CosmosDB_mongodb_connect
WITH ( 
LOCATION = 'mongodb://comsodb.mongo.cosmos.azure.com:10255', 
CREDENTIAL = azure_cosmos_db_cred_using_mongodb_connect_string ) 


CREATE EXTERNAL TABLE Cosmosdb_doc_mongodb_test (
[_id] NVARCHAR(24) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, 
[id] NVARCHAR(100) COLLATE SQL_Latin1_General_CP1_CI_AS 
)
WITH
(

LOCATION='sgcosdb.sgcosdbcnt', 
DATA_SOURCE = AZ_CosmosDB_mongodb_connect ) 


Msg 105083, Level 16, State 1, Line 13
105083;The following columns in the user defined schema are incompatible with the external table schema for table 'Cosmosdb_doc_mongodb_test': user defined column: 'id' was not found in the external table. The detected external table schema is: ([_id] NVARCHAR(24) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL).


How to get the information why SQL server and windows server went hung state?

$
0
0

Hello Experts,

 

SQL server is in windows cluster 2012 and it is in VM ware. Some times this server is going hung state and it is fail over to another node with out showing any error message. 

 

And there was no activity in background to at least to assume there is something. 

 

But last time i heard that it is because of Vmotion and holding sql server log files and trying to move to another vm node.  But this time there is no error message but sql went to stopped state. 

 

Is there any method to capture the information why sql server and windows server is going to hung state? 

 

 

 

This is the large error message i found it before it went to stopped state.

 

 

Cluster resource 'SQL Server' of type 'SQL Server' in clustered role 'SQL Server (MSSQLSERVER)' failed.

Based on the failure policies for the resource and role, the cluster service may try to bring the resource online on this node or move the group to another node of the cluster and then restart it. Check the resource and group state using Failover Cluster Manager or the Get-ClusterResource Windows PowerShell cmdlet.

SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.)

$
0
0
Hello Experts,

        We have SQL Server 2012 on Windows server 2012 Failover cluster(VM).  Few days back we have installed Anti virus on Cluster nodes and got the error SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.) Later we removed antivirus on both nodes. After couple of days again we started getting the same error and sql services are goes to stopped state. And if i perform failover then sql services are starting . Then after couple of hours later again it went to stopped state with the same error. This happened quite frequently in Node2 but on Node 1 it is happening very rarely.  Both nodes has different service packs and Windows CU.

Initially we thought it could be AV and now we completely removed still we are facing the same issue. 

Please help me to solve this nightmare issue.  



system error log

1:20:30 am

BackupIoRequest::ReportIoError: write failure on backup device 'G:\Backup\Dif_bkp\SCMDB_backup_2019_08_14_010128_7899718.bak'. Operating system error 170(The requested resource is in use.).

1:20:30 am

SQLServerLogMgr::LogWriter: Operating system error 170(The requested resource is in use.) encountered.

1:20:30 am 

The log for database 'msdb' is not available. Check the event log for related error messages. Resolve any errors and restart the database.

1:20:30 am 

The system failed to flush data to the transaction log. Corruption may occur in VolumeId: G:, DeviceName: \Device\HarddiskVolume5.
({Device Busy}
The device is currently busy.)

1:20:31 am 

The system failed to flush data to the transaction log. Corruption may occur in VolumeId: H:, DeviceName: \Device\HarddiskVolume3.
({Device Busy}
The device is currently busy.)

SQL Server Errorlog- 

Date,Source,Severity,Message
08/14/2019 07:21:10,spid6s,Unknown,SQL Server shutdown has been initiated
08/14/2019 07:21:10,spid6s,Unknown,Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup<c/> repair it<c/> or rebuild it. For more information about how to rebuild the master database<c/> see SQL Server Books Online.
08/14/2019 07:21:10,spid6s,Unknown,Operating system error 170(The requested resource is in use.) on file "H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf" during FixupLogTail.
08/14/2019 07:21:10,spid6s,Unknown,Error: 5159<c/> Severity: 24<c/> State: 13.
08/14/2019 07:21:10,spid6s,Unknown,SQLServerLogMgr::FixupLogTail: Operating system error 170(The requested resource is in use.) encountered.
08/14/2019 07:21:10,spid6s,Unknown,Error: 17053<c/> Severity: 16<c/> State: 1.
08/14/2019 07:21:10,spid6s,Unknown,fcb status 0x42<c/> handle 0x00000000000007A8<c/> size 224 pages
08/14/2019 07:21:10,spid6s,Unknown,blankSize 0x3c0000<c/> blkOffset 0x11a<c/> fileSeqNo 884<c/> totBytesWritten 0x0
08/14/2019 07:21:10,spid6s,Unknown,SQLServerLogMgr::FixupLogTail (failure): alignBuf 0x000000001163E000<c/> writeSize 0xc00<c/> filePos 0x63400
08/14/2019 07:21:10,spid6s,Unknown,374 transactions rolled forward in database 'master' (1:0). This is an informational message only. No user action is required.
08/14/2019 07:21:10,spid6s,Unknown,Starting up database 'master'.
08/14/2019 07:21:10,Server,Unknown,Software Usage Metrics is disabled.
08/14/2019 07:21:10,Server,Unknown,CLR version v4.0.30319 loaded.
08/14/2019 07:21:10,Server,Unknown,Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
08/14/2019 07:21:10,Server,Unknown,Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
08/14/2019 07:21:10,Server,Unknown,Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
08/14/2019 07:21:10,Server,Unknown,This instance of SQL Server last reported using a process ID of 11160 at 8/14/2019 7:21:08 AM (local) 8/14/2019 3:21:08 AM (UTC). This is an informational message only; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Using conventional memory in the memory manager.
08/14/2019 07:21:09,Server,Unknown,Detected 49151 MB of RAM. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
08/14/2019 07:21:09,Server,Unknown,SQL Server detected 1 sockets with 4 cores per socket and 4 logical processors per socket<c/> 4 total logical processors; using 4 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Command Line Startup Parameters:<nl/>-s "MSSQLSERVER"
08/14/2019 07:21:09,Server,Unknown,Registry startup parameters: <nl/>-d H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\master.mdf<nl/>-e H:\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG<nl/>-l H:\MSSQL11.MSSQLSERVER\MSSQL\DATA\mastlog.ldf
08/14/2019 07:21:09,Server,Unknown,The service account is 'account\sqlservice'. This is an informational message; no user action is required.
08/14/2019 07:21:09,Server,Unknown,Logging SQL Server messages in file 'H:\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG'.
08/14/2019 07:21:09,Server,Unknown,Authentication mode is MIXED.
08/14/2019 07:21:09,Server,Unknown,System Manufacturer: 'VMware<c/> Inc.'<c/> System Model: 'VMware Virtual Platform'.
08/14/2019 07:21:09,Server,Unknown,Server process ID is 5280.
08/14/2019 07:21:09,Server,Unknown,All rights reserved.
08/14/2019 07:21:09,Server,Unknown,(c) Microsoft Corporation.
08/14/2019 07:21:09,Server,Unknown,Microsoft SQL Server 2012 (SP4) (KB4018073) - 11.0.7001.0 (X64) <nl/>Aug 15 2017 10:23:29 <nl/>Copyright (c) Microsoft Corporation<nl/>Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)



Thank you

Sai Nadh

SQLServer 2019 BDC comparision

$
0
0

All,

I have to come up with a comparison for SQLServer 2019 BDC. What other softwares can it be compared with (both Vendor based and OpenSource)?

Thanks,

gopi


SQL Server 2016 SP2 > Database mail not sending mails.

$
0
0

Hi All.

I have several sql server instances running SQL Server 2016, sp2

Microsoft SQL Server 2016 (SP2-GDR) (KB4532097) - 13.0.5102.14 (X64)   Dec 31 2019 22:39:35   Copyright (c) Microsoft Corporation  Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2016 Standard 10.0<X64> (Build 14393: ) (Hypervisor)

I have configured SQL Server Database mail but my mail is not sending to recipient.

As per some blogs there were mail issues with SP1 where it should have .NET 3.5 framework should installed but mine is SP2 and it has all the same sign like SP1 mail issue.

When I launch DatabaseMail.exe in binn folder I see this error 

The following feature couldnt be installed

.NET Framework 3.5 (Include .NET 2.0 and 3.0)

As per this workaround 

https://support.microsoft.com/en-gb/help/3186435/sql-server-2016-database-mail-doesn-t-work-when-net-framework-3-5

I opted for Workaround 1 and placed the DatabaseMail.exe.config to same bill folder and now when I launch DatabaseMail.exe Its is opening a black console window, I think that was expectation so I thought now my mail issue is gone but then I still have the issue.

Though the .NET 3.5 Framework issues was related to SP1 but I have the same symptom where as I have SP2.

Help me to get rid this issue.. There are few constraint though .. 

I can not ask for install .NET 3.5 framework as I didn't fine any blog where it is saying the issue could be with SP2 also.

I can not ask for repair SQL Server.

getting error related to quoted identifiers on computed columns

$
0
0

hi we run 2014 standard.  does anybody know what this error means? its definitely related to a computed column i just added over which a non clustered unique index was built.  the computed column is called RVcast which is simply a cast of another recently added rowversion column into bigint.

---> System.Data.SqlClient.SqlException: INSERT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.


is buffer pool extension (BPE) needed if my database is already on SSD?

$
0
0

Hi gurus,

My environment is sql server 2016 EE with 64GB memory and I have one and only one 500GB OLTP database with both data and log files on SSD drives already.

If I add an additional SSD drive (same performance as the existing SSD drives for the db data/log files) and use it for BPE feature, will it improve sql server performance?

At first thought, it seems no benefit as this new SSD is the same as the existing SSD drives.

But my argument is with BPE enabled, this new SSD drives will at least serve two purposes:

1. It may reduce the dirty page flushing frequency. With a very small BP, the flushing frequency should be higher than that with a bigger BP

2. It actually increases the I/O bandwidth for the whole database because otherwise (i.e. without BPE and the regular memory BP is already full),  sql server will go to database data drive to read data, and this in theory can compete with other database transactions for I/O bandwidth.

Does anyone have any comments on whether my argument is valid?

Thanks in advance for your help.

SQL Server 2019 Getting error String or binary data would be truncated

$
0
0

Hello colleagues!

Following my question in Project Server forum in this thread https://social.technet.microsoft.com/Forums/en-US/e3167ffc-f7f0-43ac-90a7-a01c7c7db270/project-server-2019-submitted-but-not-approved-workhours I got error

String orbinary data would be truncated.

in this my script

--------------------------------------------------------------------------------------------------------
-- DECLARE TABLES
--------------------------------------------------------------------------------------------------------
DECLARE @DataBegin DATETIME, @DataEnd DATETIME
DECLARE @t TABLE (ASSN_TRANS_UID UNIQUEIDENTIFIER, ASSN_TRANS_ACTION_ENUM INT) 
DECLARE @m TABLE (ASSN_UID UNIQUEIDENTIFIER, RES_SAVED_DATE INT, h FLOAT, ASSN_TRANS_SUBMIT_DATE DATE, ASSN_TRANS_ACTION_ENUM INT)
DECLARE @fin TABLE (ASSN_UID UNIQUEIDENTIFIER, RES_SAVED_DATE DATE, h FLOAT, ASSN_TRANS_SUBMIT_DATE DATE, TASK_UID UNIQUEIDENTIFIER, PROJ_UID UNIQUEIDENTIFIER, RES_UID UNIQUEIDENTIFIER)
DECLARE @report TABLE (AssignmentUID UNIQUEIDENTIFIER, TimeByDay DATE, ProjectUID UNIQUEIDENTIFIER, TaskUID UNIQUEIDENTIFIER, AssignmentActualWork FLOAT, ResourceUID UNIQUEIDENTIFIER)
DECLARE @upselect TABLE (ASSN_UID UNIQUEIDENTIFIER, RES_SAVED_DATE DATE, TASK_UID UNIQUEIDENTIFIER, PROJ_UID UNIQUEIDENTIFIER, RES_UID UNIQUEIDENTIFIER)
DECLARE @tasksel TABLE (ASSN_UID UNIQUEIDENTIFIER, TASK_NAME VARCHAR)

SET DATEFORMAT dmy 
SET @DataBegin = '07-07-2020' 
SET @DataEnd = '21-07-2020' 

--------------------------------------------------------------------------------------------------------
-- COLLECTING SUBMITTED DATA
--------------------------------------------------------------------------------------------------------

INSERT @t 
SELECT 
		at.ASSN_TRANS_UID, 
		at.ASSN_TRANS_ACTION_ENUM 
FROM 
		(SELECT 
				ASSN_UID, 
				ASSN_TRANS_UID, 
				ASSN_TRANS_ACTION_ENUM 
		FROM 
				pjpub.MSP_ASSIGNMENT_TRANSACTIONS 
		WHERE 
					(1=1)
--				AND 
--					ASSN_TRANS_STATE_ENUM LIKE 0	-- 0 - task update
													-- 1 - request rejection
													-- 2 - create task
													-- 3 - re-assign
													-- 4 - create assing
													-- 5 - re-assign to team
													-- 6 - delete task
													-- 7 - delete assigned
		) AS at 
	INNER JOIN 
			(SELECT 
					ISNULL(ass.ASSN_UID, a.ASSN_UID) [ASSN_UID] 
			FROM 
					pjpub.MSP_ASSIGNMENTS_SAVED ass 
				FULL JOIN 
						pjpub.MSP_ASSIGNMENTS a 
					ON 
						(ass.ASSN_UID = a.ASSN_UID) 
			WHERE 
					ISNULL(ass.ASSN_FINISH_DATE, a.ASSN_FINISH_DATE) >= @DataBegin 
				AND 
					ISNULL(ass.ASSN_START_DATE, a.ASSN_START_DATE) < @DataEnd+1 
			) AS tm 
		ON 
			at.ASSN_UID = tm.ASSN_UID 

--------------------------------------------------------------------------------------------------------
-- SENDING DATA TO THE FUNCTION
--------------------------------------------------------------------------------------------------------

INSERT @m 
SELECT 
		f.*, t.ASSN_TRANS_ACTION_ENUM	-- in results:	0 - submitted
										--				1 - approved
										--				2 - rejected
FROM 
		@t t CROSS APPLY dbo.SPK_ASSN_CHANGE_DATA (t.ASSN_TRANS_UID) f 
WHERE
		t.ASSN_TRANS_ACTION_ENUM IN ('0', '1')

--------------------------------------------------------------------------------------------------------
-- CONVERTING RES_SAVED_DATE
--------------------------------------------------------------------------------------------------------
INSERT @fin
SELECT
			tfin.ASSN_UID,
			DATEADD(dd,RES_SAVED_DATE, '19831231') AS RES_SAVED_DATE, 
			h AS h, 
			ASSN_TRANS_SUBMIT_DATE,
			SaveTable.TASK_UID,
			PROJ_UID,
			RES_UID
FROM
			@m tfin
	LEFT JOIN
			pjpub.MSP_ASSIGNMENTS_SAVED SaveTable
		ON
			tfin.ASSN_UID = SaveTable.ASSN_UID
WHERE 
			RES_SAVED_DATE >= DATEDIFF (DD,'19831231', @DataBegin) 
		AND 
			RES_SAVED_DATE <= DATEDIFF (DD,'19831231', @DataEnd)

--------------------------------------------------------------------------------------------------------
-- PREPARING REPORTING DATA
--------------------------------------------------------------------------------------------------------

INSERT @report
SELECT
			AssView.AssignmentUID AS AssignmentUID,
			AssView.TimeByDay AS TimeByDay, 
			ProjView.ProjectUID AS ProjectUID,
			TaskView.TaskUID AS TaskUID,
			AssignmentActualWork = SUM(AssView.AssignmentActualWork),
			ResView.ResourceUID AS ResourceUID
FROM
			dbo.MSP_EpmAssignmentByDay_Reports_UserView AssView
	LEFT JOIN 
			pjrep.MSP_EpmAssignment AssTable
		ON 
			AssView.AssignmentUID = AssTable.AssignmentUID
	LEFT JOIN 
			dbo.MSP_CustomViewReports_EpmResource_UserView ResView
		ON 
			AssTable.ResourceUID = ResView.ResourceUID
	LEFT JOIN 
			dbo.MSP_CustomViewReports_EpmProject_UserView ProjView
		ON 
			AssTable.ProjectUID = ProjView.ProjectUID
	LEFT JOIN 
			dbo.MSP_CustomViewReports_EpmTask_UserView TaskView
		ON 
			AssTable.TaskUID = TaskView.TaskUID
WHERE
			(1 = 1)
--		AND 
--			ResourceName IN ('Shuklin Roman')
		AND 
			(TimeByDay > @DataBegin AND TimeByDay < @DataEnd)
		AND 
			(AssView.AssignmentActualWork > 0.0)
GROUP BY 
			AssView.AssignmentUID,
			AssView.TimeByDay,
			ResView.ResourceUID,
			ProjView.ProjectUID,
			TaskView.TaskUID
--------------------------------------------------------------------------------------------------------
-- UNION ALL PUB AND REP UIDS
--------------------------------------------------------------------------------------------------------

INSERT @upselect
SELECT
			ASSN_UID, 
			RES_SAVED_DATE, 
			TASK_UID, 
			PROJ_UID,
			RES_UID
FROM
			@fin
UNION
			ALL
SELECT
			AssignmentUID, 
			TimeByDay, 
			TaskUID, 
			ProjectUID,
			ResourceUID
FROM
			@report

--------------------------------------------------------------------------------------------------------
-- GETTING TASKS
--------------------------------------------------------------------------------------------------------
INSERT @tasksel
SELECT
			ASSN_UID,
			TASK_NAME
FROM
			pjpub.MSP_ASSIGNMENTS_SAVED
UNION
			ALL
SELECT
			AssignmentUID,
			TaskName
FROM
			dbo.MSP_CustomViewReports_EpmAssignment_UserView AssView
	LEFT JOIN
			dbo.MSP_CustomViewReports_EpmTask_UserView TaskView
		ON	
			AssView.TaskUID = TaskView.TaskUID


--------------------------------------------------------------------------------------------------------
-- GENERATING FINAL REPORT
--------------------------------------------------------------------------------------------------------
SELECT
			upsel.PROJ_UID AS P_UID,
			upsel.RES_UID AS R_UID,
			ResView.ResourceName AS ResourceName,
			upsel.RES_SAVED_DATE AS TBD,
			upsel.ASSN_UID AS A_UID,
			upsel.TASK_UID AS T_UID,
			tasksel.TASK_NAME AS T_NAME,
			tfin.h AS SH,
			AssView.AssignmentActualWork AS AH
			
FROM
			@upselect upsel
	LEFT JOIN
			@fin tfin
		ON 
			upsel.ASSN_UID = tfin.ASSN_UID
	LEFT JOIN
			@report AssView
		ON
			upsel.ASSN_UID = AssView.AssignmentUID 
	LEFT JOIN
			@tasksel tasksel
		ON
			upsel.ASSN_UID = tasksel.ASSN_UID
	LEFT JOIN
			dbo.MSP_CustomViewReports_EpmResource_UserView ResView
		ON
			upsel.RES_UID = ResView.ResourceUID
WHERE
			(1=1)
		AND
			ResView.ResourceName IN ('Kucherovsky Andrey')
GROUP BY
			upsel.PROJ_UID,
			upsel.RES_UID,
			ResView.ResourceName,
			upsel.RES_SAVED_DATE,
			upsel.ASSN_UID,
			upsel.TASK_UID,
			tasksel.TASK_NAME,
			tfin.h,
			AssView.AssignmentActualWork

But error in result

(4314 rows affected)

(12388 rows affected)

(2852 rows affected)

(1342 rows affected)

(4194 rows affected)
Msg 8152, Level 16, State 30, Line 151
String or binary data would be truncated.
The statement has been terminated.

(2 rows affected)

Completion time: 2020-07-21T12:56:59.1425071+03:00

The Line 151 it's RES_UID in this select

INSERT @upselect
SELECT
			ASSN_UID, 
			RES_SAVED_DATE, 
			TASK_UID, 
			PROJ_UID,
			RES_UID
FROM
			@fin

By DECLARE the tables @fin and @upselect have RES_UID column as UNIQUEIDENTIFIER type.

Original RES_UID we're getting from pjpub.MSP_ASSIGNMENTS_SAVED in this select

INSERT @fin
SELECT
			mt.ASSN_UID,
			DATEADD(dd,RES_SAVED_DATE, '19831231') AS RES_SAVED_DATE, 
			h AS h, 
			ASSN_TRANS_SUBMIT_DATE,
			SaveTable.TASK_UID,
			PROJ_UID,
			RES_UID
FROM
			@m mt
	LEFT JOIN
			pjpub.MSP_ASSIGNMENTS_SAVED SaveTable
		ON
			mt.ASSN_UID = SaveTable.ASSN_UID
The RES_UID from pjpub.MSP_ASSIGNMENTS_SAVED is UNIQUEIDENTIFIER type too.

So, colleagues, what's wrong data types?


MCSA: Security; MCTP: Microsoft ISA 2006


do xml comparisons really rely on ansi_nulls setting ?

$
0
0

hi we run 2014 std.  we re going thru an exercise of introducing an index o a computed column.

we already saw and probably repaired issues related to quoted identifier being off.

now we get the error you see below after changing ansi_nulls to "on" from "off" on a proc...the offending statement that probably always worked fine when it was ff looked something like this...@file_xml is data type xml...i didnt see anything in the article i read on ansi_nulls about xml, but thats just one article and perhaps about a newer version of sql...

WHERE some_ID = ISNULL(@some_ID,some_ID) AND

                FILE_NAME = ISNULL(@FILE_NAME,FILE_NAME) AND

               FILE_XML = @FILE_XML AND

Msg 305, Level 16, State 1, Procedure mygeneratedproc, Line 1480

The XML data type cannot be compared or sorted, except when using the IS NULL operator.

** An error was encountered during execution of batch. Exiting.

Non Yielding Schduler on SQL 2019 relating to bug in UDF Scalar inlining

$
0
0
I asked this question here previously: https://social.msdn.microsoft.com/Forums/en-US/7d6df408-4c65-42f4-9666-2db0623100f8/nonyielding-scheduler-on-sql-server-2019?forum=sqldatabaseengine

However the answer indicated it would likely be fixed in CU2... it's now CU5 and we still have the same issue.

Repro here:
CREATE FUNCTION [dbo].[fn_remove_nonstandard_characters]
  (
    @p_string_to_cleanse   varchar(1000)
  )
  RETURNS varchar(1000)
  AS
  --===============================================================================
  --   removes nonstandard characters from string (except commas and dashes)
  --===============================================================================
  BEGIN
    DECLARE @v_nonstandard_character_mask   varchar(110)

    SET @v_nonstandard_character_mask = '%[!?\"$.;:*#()@\\]%'

    WHILE @p_string_to_cleanse LIKE @v_nonstandard_character_mask
      BEGIN
         SET @p_string_to_cleanse = LEFT( @p_string_to_cleanse,
                                          PATINDEX( @v_nonstandard_character_mask,
                                          @p_string_to_cleanse )-1 )
    + REVERSE( LEFT( REVERSE( @p_string_to_cleanse),
                                          LEN( @p_string_to_cleanse ) -
                                          PATINDEX( @v_nonstandard_character_mask, @p_string_to_cleanse )))
      END

  --===============================================================================
  --   removes commas and dashes characters from string
  --===============================================================================
    IF @p_string_to_cleanse LIKE '%,%'
      SET @p_string_to_cleanse = REPLACE( @p_string_to_cleanse, ',', '' )

    IF @p_string_to_cleanse LIKE '%-%'
      SET @p_string_to_cleanse = REPLACE( @p_string_to_cleanse, '-', '' )

    IF @p_string_to_cleanse LIKE '%''%'
      SET @p_string_to_cleanse = REPLACE( @p_string_to_cleanse, '''', '' )

    IF @p_string_to_cleanse LIKE '%~[%' ESCAPE '~'
      SET @p_string_to_cleanse = REPLACE( @p_string_to_cleanse, '[', '' )

    IF @p_string_to_cleanse LIKE '%]%'
      SET @p_string_to_cleanse = REPLACE( @p_string_to_cleanse, ']', '' )

    IF @p_string_to_cleanse LIKE '%`%'
      SET @p_string_to_cleanse = REPLACE( @p_string_to_cleanse, '`', '' )
            
    RETURN @p_string_to_cleanse
  END



CREATE FUNCTION [dbo].[fn_pack_legal_name]
(
  @p_legal_name	      varchar(1000)
, @p_max_return_length  integer
)
RETURNS varchar(1000)
AS

--===============================================================================
--	removes the following terms from employer_name
--	AND, MANAGEMENT, LTD, LIMITED, GROUP, COMPANY, CO, DIVISION, NEW ZEALAND, NZ, MR, MRS
--===============================================================================
  BEGIN
    SET @p_legal_name = dbo.fn_remove_nonstandard_characters( @p_legal_name )

    IF @p_legal_name LIKE '% AND%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' AND', ' ' )

    IF @p_legal_name LIKE '% MANAGEMENT%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' MANAGEMENT', ' ' )

    IF @p_legal_name LIKE '% LTD%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' LTD', ' ' )

    IF @p_legal_name LIKE '% LIMITED%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' LIMITED', ' ' )

    IF @p_legal_name LIKE '% GROUP%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' GROUP', ' ' )

    IF @p_legal_name LIKE '% COMPANY%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' COMPANY', ' ' )

    IF @p_legal_name LIKE '% CO %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' CO ', ' ' )

    IF @p_legal_name LIKE '% DIVISION%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' DIVISION', ' ' )

    IF @p_legal_name LIKE '%NEW ZEALAND%'
		  SET @p_legal_name = REPLACE( @p_legal_name, 'NEW ZEALAND', ' ' )

    IF @p_legal_name LIKE '% NZ%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' NZ', ' ' )

    IF @p_legal_name LIKE '% MRS%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' MRS', ' ' )

    IF @p_legal_name LIKE '% MR%'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' MR', ' ' )
--lbf repair
    IF @p_legal_name LIKE '% AN %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' AN ', ' ' )

    IF @p_legal_name LIKE '% AS %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' AS ', ' ' )

    IF @p_legal_name LIKE '% AT %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' AT ', ' ' )

    IF @p_legal_name LIKE '% BY %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' BY ', ' ' )

    IF @p_legal_name LIKE '% FOR %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' FOR ', ' ' )

    IF @p_legal_name LIKE '% FROM %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' FROM ', ' ' )

    IF @p_legal_name LIKE '% IN %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' IN ', ' ' )

    IF @p_legal_name LIKE '% OF %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' OF ', ' ' )

    IF @p_legal_name LIKE '% ON %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' OF ', ' ' )

    IF @p_legal_name LIKE '% OR %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' OR ', ' ' )

    IF @p_legal_name LIKE '% THE %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' THE ', ' ' )

    IF @p_legal_name LIKE '% TO %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' TO ', ' ' )

    IF @p_legal_name LIKE '% WITH %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' WITH ', ' ' )

    IF @p_legal_name LIKE '% COMP %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' COMP ', ' ' )

    IF @p_legal_name LIKE '% COMPAN %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' COMPAN ', ' ' )

    IF @p_legal_name LIKE '% COMPANIES %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' COMPANIES ', ' ' )

    IF @p_legal_name LIKE '% COMPANY %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' COMPANY ', ' ' )

    IF @p_legal_name LIKE '% COMPNY %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' COMPNY ', ' ' )

    IF @p_legal_name LIKE '% CORP %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' CORP ', ' ' )

    IF @p_legal_name LIKE '% PTY %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' PTY ', ' ' )

    IF @p_legal_name LIKE '% CORPORATION %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' CORPORATION ', ' ' )

    IF @p_legal_name LIKE '% INC %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' INC ', ' ' )

    IF @p_legal_name LIKE '% INCORP %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' INCORP ', ' ' )

    IF @p_legal_name LIKE '% INCORPORATED %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' INCORPORATED ', ' ' )

    IF @p_legal_name LIKE '% PROPRIETARY %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' PROPRIETARY ', ' ' )

    IF @p_legal_name LIKE '% LMTD %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' LMTD ', ' ' )

    IF @p_legal_name LIKE '% NL %'
		  SET @p_legal_name = REPLACE( @p_legal_name, ' NL ', ' ' )

    SET @p_legal_name = UPPER( LEFT( REPLACE( @p_legal_name, ' ', '' ), @p_max_return_length) )

    RETURN @p_legal_name
  END


--Now lets run these functions using a simple table:

DROP TABLE IF EXISTS dbo.Function_calling_function

CREATE TABLE dbo.Function_calling_function (
	ID int IDENTITY(1,1) PRIMARY KEY,
	CompanyName varchar(300)
)

INSERT INTO dbo.Function_calling_function (CompanyName)
VALUES ('Microsoft software LMTD'),('Amazon shopping [.com] limited'),('Gillette, shaving foam limited'),('Facebook.com'),('New Zealand company inc'),('Xero'),('Some [],; Company')

--Try selecting everything, works a-ok
SELECT * FROM dbo.Function_calling_function

--Try non nested scalar function, works a-ok
SELECT *, [dbo].[fn_remove_nonstandard_characters](CompanyName) FROM dbo.Function_calling_function

--Try nested scalar function, seems to never end
SELECT *, [dbo].[fn_pack_legal_name](CompanyName,200) as CheckNestedFunc FROM dbo.Function_calling_function



I would prefer we didn't have to turn off Scalar UDF inlining per database, but that is what we have done.  It's not an option to review the hundreds of calls to these functions and provide query hints or to selectively turn off the feature for certain functions as we don't know what will/will not cause the bug. It seems to be related to nesting a "inlineable" function with a "non inlineable" function.  Prefer it was fixed!


Is it common / best practise on installing Instance Root on different drive ?

$
0
0

Is it common / best practise on installing Instance Root on different drive ?


Fehler Initialisierung sqlcmd_Bibliothek

$
0
0

Der Aufruf von sp_send_dbmail mit einer Query funktioniert im SQL-Server Management Studio.

Der gleiche Aufruf in einem Schritt eines SQL-Agent-Auftrages bringt die Fehlermeldung

. Fehler bei der Initialisierung von sqlcmd-Bibliothek. Fehlernummer: -2147467259. [SQLSTATE 42000] (Fehler 22050)

Ein Aufruf dagegen ohne Query von sp_send_dbmail im SQL-Agent funktioniert.

Dem SQL-Agent sind Mailkonto und -profil zugewiesen.

Was fehlt

Custom String split function issue

$
0
0

I have an application that must support some holdouts still on SQL Server 2012, pre-2016 so I cannot use the SQL Server 2016 native function STRING_SPLIT function. Furthermore, I need to implement a 2 char delimiter as well

For this, I am using an in-line function derivative of : http://www.sommarskog.se/arrays-in-sql-2000.html#tblnum

The function works fine in most circumstances except one in which the input array list is nvarchar(max) and the delimiter is 2 char, and there is a where clause on the function

this reproduces on

-- Microsoft SQL Server 2017 (RTM-CU21) (KB4557397) - 14.0.3335.7 (X64)   
-- Microsoft SQL Server 2019 (RTM-CU5) (KB4552255) - 15.0.4043.16 (X64) 


full code to reproduce below:

CREATE TABLE dbo.Nums ( I int NOT NULL, CONSTRAINT PK_Nums PRIMARY KEY CLUSTERED (I) )
GO
-- populate new Nums table to support string split
SET NOCOUNT ON
DECLARE @I int = 1, @Mx int = 0, @Cnt int = 0

       WHILE (@I <= 10100) BEGIN
       IF NOT EXISTS( SELECT * FROM dbo.Nums WHERE I = @I) 
        INSERT dbo.Nums VALUES(@I)
       SET @I = @I + 1
       END
GO
ALTER INDEX ALL ON dbo.Nums REBUILD
SELECT COUNT(*) FROM dbo.Nums
GO
CREATE FUNCTION dbo.fnSplitString4 (@string nvarchar(4000), @delimiter NCHAR(1))   
RETURNS TABLE AS  
RETURN(  
 SELECT DISTINCT substring(CONCAT(@delimiter, @string, @delimiter), n.I + 1, charindex(@delimiter, CONCAT(@delimiter, @string, @delimiter), n.I + 1) - n.I - 1) AS splitdata, n.I  
 FROM dbo.Nums n  
 WHERE ISNULL(@string,'')<>'' AND   n.I <= len(CONCAT(@delimiter, @string, @delimiter)) - 1 AND substring(CONCAT(@delimiter, @string, @delimiter), n.I, 1) = @delimiter  
)  
--- http://www.sommarskog.se/arrays-in-sql-2000.html#tblnum  
GO
CREATE FUNCTION dbo.fnSplitStringX (@string nvarchar(max), @delimiter NCHAR(1))   
RETURNS TABLE AS  
RETURN(  
 SELECT DISTINCT substring(CONCAT(@delimiter, @string, @delimiter), n.I + 1, charindex(@delimiter, CONCAT(@delimiter, @string, @delimiter), n.I + 1) - n.I - 1) AS splitdata, n.I  
 FROM dbo.Nums n  
 WHERE ISNULL(@string,'')<>'' AND   n.I <= len(CONCAT(@delimiter, @string, @delimiter)) - 1 AND substring(CONCAT(@delimiter, @string, @delimiter), n.I, 1) = @delimiter  
)  
--- http://www.sommarskog.se/arrays-in-sql-2000.html#tblnum  
GO
CREATE OR ALTER FUNCTION dbo.fnSplitString24 ( @string NVARCHAR(4000), @delimiter NCHAR(2) ) 
RETURNS TABLE AS
RETURN(
SELECT substring(CONCAT(@delimiter, @string, @delimiter), n.I + 2, charindex(@delimiter, CONCAT(@delimiter, @string, @delimiter), n.I + 2) - n.I - 2) AS splitdata, n.I
FROM dbo.Nums n
WHERE ISNULL(@string,'')<>'' AND  n.I <= len(CONCAT(@delimiter, @string, @delimiter)) - 2 AND substring(CONCAT(@delimiter, @string, @delimiter), n.I, 2) = @delimiter
)
--- http://www.sommarskog.se/arrays-in-sql-2000.html#tblnum
GO
CREATE OR ALTER FUNCTION dbo.fnSplitString2X ( @string NVARCHAR(max), @delimiter NCHAR(2) ) 
RETURNS TABLE AS
RETURN(
SELECT substring(CONCAT(@delimiter, @string, @delimiter), n.I + 2, charindex(@delimiter, CONCAT(@delimiter, @string, @delimiter), n.I + 2) - n.I - 2) AS splitdata, n.I
FROM dbo.Nums n
WHERE ISNULL(@string,'')<>'' AND  n.I <= len(CONCAT(@delimiter, @string, @delimiter)) - 2 AND substring(CONCAT(@delimiter, @string, @delimiter), n.I, 2) = @delimiter
)
--- http://www.sommarskog.se/arrays-in-sql-2000.html#tblnum
GO

-- All of the below works

SELECT value FROM  STRING_SPLIT (N'11;',N';')
WHERE value IS NOT NULL

SELECT TRY_CONVERT(int, splitdata) splitdata 
FROM dbo.fnSplitString4(N'11',N';')
WHERE splitdata IS NOT NULL

SELECT TRY_CONVERT(int, splitdata) splitdata 
FROM dbo.fnSplitStringX(N'11',N';')
WHERE splitdata IS NOT NULL

SELECT TRY_CONVERT(int, splitdata) splitdata 
FROM dbo.fnSplitString24(N'11',N';#')
WHERE splitdata IS NOT NULL

SELECT TRY_CONVERT(int, splitdata) splitdata 
FROM dbo.fnSplitString2X(N'11',N';#')

--WHERE splitdata IS NOT NULL

--What does not work is :

SELECT TRY_CONVERT(int, splitdata) splitdata 
FROM dbo.fnSplitString2X(N'11',N';#')
WHERE splitdata IS NOT NULL

-- error message is

Msg 537, Level 16, State 3, Line 87
Invalid length parameter passed to the LEFT or SUBSTRING function.

-- note: the correct result is return, but so is the message

also: the hint has no effect

OPTION (USE HINT('DISABLE_TSQL_SCALAR_UDF_INLINING'));


jchang


difference between SET STATISTICS XML and ACTUAL execution plan

$
0
0

what's the difference between the output of query when SET STATISTICS XML ON 

or 

In ssms enable "actual query plan "?

Lazy writer Issue

$
0
0

Hello All,

We have a SQL Production box , i am observing 00:00 AM daily the PLE automatic goes near about 5 and lazy writer occurs during that time. and when the lazy writer occurs it slows all the query for some time. i have checked and found some delete queries are schedule to delete the records from live table and it scheduled at 00:00, i thought that delete query may be the culprit and i have delayed in the schedule to 10 min but still PLE again reached between 0 to 10 at same time , could you please help me to solve the issue? Let me know if you require anything to check the issue.

     Br

ChetanV

SQL Server 2016 Database - Small Index Causing Poor Performance

$
0
0
Hello. I have a small index with <4% fragmentation and only 85 pages. This index is causing performance issues for end users. The scheduled DB maintenance doesn't reorganize or rebuild this index since it doesn't qualify for that based on the given criteria. However when I manually rebuild it, the query that runs for over 40 secs runs below 1 sec. I have forced this index to rebuild specifically as part of the nightly maintenance, however users still experience slowness up until I manually rebuild it again (online). I can schedule it at a granular level, but there must be something else going on that has the impact. This database is on SQL 2016 on premises with .NET app accessing it. Thanks.
Viewing all 15930 articles
Browse latest View live


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