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

sp_send_dbmail sending out extra spaces with @query output

$
0
0

Hi al, I can across this a couple days ago (and after about six hours of banging my head sifting through my code in order to find where these extra spaces where coming from it dawned on me that the sp_send_dbmail sp was making a call via the @query parameter that in turned returns the result set back to he local API that then sends the email.

 

in a nut shell I have built a process that monitor SQL server plans and looks for plans that exceed a set list of thresholds. once identified I wrap all the necessary detail into a nice little html string and stuff it into a table that is later called with a mailhandleid by the @query parameter.

 

what breaks(and its not huge, but make the outputted code marked with a few syntax errors like formatting and string names being seperated.)

 

Here is the sp call and the @bodycmd parameter is a simple select of a single column from the mailstring table

sp_send_dbmail

 

Code Snippet

begin

try

EXECUTE

[msdb].[dbo].[sp_send_dbmail]

@profile_name

='DBMonitor'

,@recipients ='dbmonitor@abc.com'

,@subject = @subjectcmd

,@body_format ='HTML'

,@importance ='HIGH'

,@query = @bodycmd

,@query_no_truncate =1

end

try

begincatch

SET @errmsg ='Msg '+

cast(ERROR_NUMBER()asvarchar(20))+', Level '+

cast(ERROR_SEVERITY()asvarchar(20))+', State '+

cast(ERROR_STATE()asvarchar(20))+', Line '+

cast(ERROR_LINE()asvarchar(20))+', '+CHAR(13)+'Procedure '+

isnull(ERROR_PROCEDURE(),'')+CHAR(13)+isnull(ERROR_MESSAGE(),'')

endcatch

set @err =ERROR_NUMBER()

if @err <> 0

begin

print'STATUS: An Error occcured while attempting to send mail. The following error was captured: '+isnull(@errmsg,'Error:0')

end

else

begin

print'STATUS: Notification mail was sent successfully'

deletefrom ##tmp_mailstring_snapshot where msgid = @mail_handle

end

 

 

Me thinks is a BUG but hey i could be wrong...

 

Any thoughts?

Thanks


Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication.

$
0
0

Hello,

I have the in the title mentioned error in the following environment.

I have a test windows domain (2016) with some test windows servers running as members of the domain. On some of them MS SQL 2016 installed.

In addition, I installed for testing an UBUNTU Linux 16.04.3 and MS SQL Server 2017 on it. Server name is UBNTSQL / IPv4 is 10.10.11.199.

I joined the UBNTSQL server to the Kerberos realm of my domain. In “AD Users & Computers” I can find my UBNTSQL server in an extra created OU=Linux. Also in “ADSI Editor” with the distinguished name

CN=UBNTSQL,OU=Linux,DC=mytestdom,DC=mycompany,DC=com

All looks fine.

I can connect to my test SQL instance on UBUNTU assa’ with the proper password. With the local sa’ user, all is working excellent.

I can also execute the following statements:

CREATELOGIN [MYTESTDOM\MYSQLUSR]FROMWINDOWS; 

GO

 

The ’MYSQLUSR’ is an extra user, created in the MYTESTDOM. It is a member of the ’Domain Admins’ group. As the result, the login created.

 

I can also assign the new created login the ’sysadmin’ server role. I can create in my test database ‘UBNT17’ the user ’MYSQLUSR’ and map the user to the login ’MYTESTDOM\MYSQLUSR’. All working.

 

I do can login to the UBUNTU Linux as the user ’MYTESTDOM\MYSQLUSR’. It shows me, the server belongs really to the domain / realm.

 

The only thing, I cannot run, is to connect from a Windows server – member of the mentioned domain to the UBNTSQL SQL server using the integrated security.

 

I try actually the following.

1. I connect to Windows as the user ’MYTESTDOM\MYSQLUSR.

2. I start CMD and try to execute:

sqlcmd –S 10.10.11.199–d UBNT17 –E

I receive the message:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login failed.

The login is from an untrusted domain and cannot be used with Integrated authentication.

 

From the same CMD session, the following command is working excellent.

     sqlcmd –S 10.10.11.199 –U sa –P mypassword

 

The same error I receive, if I start SQL Operations Studio on Windows and try to connect:

 

System.Data.SqlClient.SqlException (0x80131904):

Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication.

  at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)

  at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)

  at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)

  at System.Data.ProviderBase.DbConnectionFactory.<>c__DisplayClass22_0.<TryGetConnection>b__0(Task`1 _)

  at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()

  at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

--- End of stack trace from previous location where exception was thrown ---

  at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)

--- End of stack trace from previous location where exception was thrown ---

  at Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.ReliableSqlConnection.<>c__DisplayClass28_0.<<OpenAsync>b__0>d.MoveNext() in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Connection\ReliableConnection\ReliableSqlConnection.cs:line 298

--- End of stack trace from previous location where exception was thrown ---

  at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.TryOpenConnection(ConnectionInfo connectionInfo, ConnectParams connectionParams) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Connection\ConnectionService.cs:line 542

ClientConnectionId:439d4b50-d1c8-40cd-9cff-39d102e125c0

Error Number:18452,State:1,Class:14

 

I will be glad to have any ideas to fix the issue.

SQL Server Synonym

$
0
0

When i create an sql server synonym why is this not visible in the Add tables dialogue box while creating a view ?

AS you can see i have created a synonym ast fact_budget_data, but in the Add table dialogue box the synonym is not visible. i have clicked on the Refresh button also, but it does not work.

Sanjay Shah

Deleted

Strange Issue with SQL server Jobs

$
0
0

We are running a SQL server job  in SQL server 2016 Enterprise Edition which is calling some procedures to insert data into some tables. While we are running the procedures individually, data insertion is always happening properly . But while we are executing the same using job, it is always failing in the middle way with the below statement "INSERT CUSTOMER LOAN RECORD FOR LOAN ID 51170007714587, COUNTER VALUE 131070 [SQLSTATE 01000] (Message 0) " . We have closely examined server resources like CPU,Memory during job execution but did not find any hint on resource shortage which can led to this job failures.Any help will be highly appreciated

Regards,
Sandip

Incorrect syntax near 'query_store'.

$
0
0

Hello,

I'm trying to enable query store on a database which has compatibility level of 100.  I just migrated it to a SQL instance which is running 2014.   I am having the error:  Incorrect syntax near 'query_store' 

when I try to run this:

alterdatabase[OverallHealth]setquery_store=on

Please advise.

Thanks,

Veena


Reg:which index takes more storage either clustered or non clustered as per the storage ...

$
0
0

Hi Experts,

As per the storage is concerned,which index  occupy more space,clustered or non clustered?

i think that clustered index takes less storage and non clustered index takes more storage when compared to clustered index. am i correct?

Thanks in Advance.

SQL Service failing to start with TCP IPV6 1433 port already in use error

$
0
0
Hi All, 

Need your advise on TCP Port in use error. 



We have a DB Server where we could see connections coming from application. But seems there are not outgoing connections to application server. 

On trying to restart SQL Service, we are facing below errors and had to keep restarting windows server each time.

"Server TCP Provider failed to listen on [any <ipv6> 1433. TCP Port already in use"

and

"TDCNIClient initializtion failed with error 0x2740, status code 0xa. Reason unable to initialize TCP/IP Listener. Only one usage of each socket address(protocol/network address/port) is normally permitted. 

On verifying netstat -a there are no connections via 1433 port when SQL Service is stopped. Please help to advise on possible cases of investigation in this case. 

SQL Server performance too slow

$
0
0

Hi All, 

We are having a sql server running on 2008 R2 and from past few days we see lot of degrade in performance. There are few blob objects but no changes done recently .Backups usually completing in 5 hrs is now taking ~2days and shrink operation  is taking ~ 3 days for releasing 2GB only so we are unable to release space onto drive.Few IO errors and memory dumps observed as well. We tried increasing RAM but issue still exists.

Please help on suggesting possible cases where we can check and improve server performance.

SQL 2017 Uisng a Lower Level Compatibility Database

$
0
0

I am currently using SQL Server 2017 and have a database that I still need to keep in a lower compatibility level - until we get ready to upgrade.  In the meantime does it make sense to use the tuning option "Forced_Last_Good_Plan"?  My understanding is I can manually use the Query Store to monitor the regressed plans for this database?  I realize in 2017 mode this will be done automatically.  So my question is - does this configuration option make sense for those databases not quite at compatibility level 140?

Thanks


Stephen Wexler

Send Email From SQL Server Database

$
0
0

Hi friends,

I have been using the google smtp server and the live mail smtp server to try to send email from my SQL Server Database. I found some instructions on how I can perform this in the following link https://www.c-sharpcorner.com/article/configure-database-mail-send-email-from-sql-server-database/. It seems very straightforward, however, I have been unable to get this functionality to work. Are there any trouble shooting tips that someone could please give me so that I can get this feature to work. Thanks !


SQL Server 2016 Large memory instance has Procedure cache clearing regularly

$
0
0
I have an issue on SQL2016 SP1 instances on Windows Server 2012R2 where despite having very large amounts of memory and seemingly no obvious memory pressures entries are regularly dropping out of the procedure cache. During core hours for the users the entries in the procedure cache only go back 30-60 minutes.

The server has 1.5TB of memory with max server memory set at 1.2TB. I've seen posts from others witnessing this issue in 2016 and the solution being to enable Locked Pages In Memory but the account SQL runs under belongs to an AD group that is enabled for LPIM and I can see from locked_page_allocations in sys.dm_os_process_memory that there's 120GB locked in memory.

Looking at perfmon Page Life Expectancy looks fine sitting at around 55000 without any spikes and available memory static around 300GB. Looking at sys.dm_os_memory_clerks the plans are taking up less than 30GB although I can see there's just under 1.1TB allocated to the data cache

The instance has a fair amount of activity but not excessive, 520 Batches/Sec on average but I have the same application on SQL2008R2 with 928GB Max memory running 2200 Batches/Sec against a 30TB DB and the procedure cache entries on there go back over 6 weeks as opposed to less than an hour on 2016.

Any ideas of why procedures are dropping out of cache so rapidly on SQL2016 and any resolutions that could apply since LPIM is already ruled out?

Maintenance Jobs , Backup jobs got slow after shifting servers.

$
0
0

Recently we have shifted our servers from one cabin to other cabin with same specs of Power , UPS & Network connections.

From next day we noticed that our SQL maintenance plans (Subplan2,3 . Sub plan 1 is running for same time) & Backup job running for long hours.

Details:

SSMS : 2008 R2  , OS : 2012 R2  , DB Size :220GB ,RAM 128Gig , SQL Allocated memory 85Gig.

Earlier Subplan 2 running time 3 Hrs 30mins ,now after shifting of servers 6hrs with locking of other application objects.

Earlier Subplan 3 running time 3Hrs 30Mins , Now running for 5Hrs 30mins.

We have disabled Subplan2 and running 1& 3 only now.

Backup earlier it used to take 35 Mins now its taking 90 mins.

What could be the issue ? Other application and server performance are running fine.

 

Reading/writing records over the internet

$
0
0

Hi guys,

I am after some help and hopefully you can point me in the right direction.

I am running SQL server 2017 database and analysis server (same VM) on Windows server 2012, IIS is installed. Currently it is being used to allow client machines that sit outside of the domain to connect to analysis services using ADOMD, I am using the msmdpump and I am using https (SSL installed and configured). Basic authentication is used and then a script maps the login to a windows domain account.

On the database side the only users that currently are allowed to read/write to the database is myself and analysis services (for writeback).

I am working on creating a Windows Application and an Android Application that will add,delete and edit records in the actual database (not analysis services). Most of the content will be text and XML.

Can I enable SQL connections over the internet (must be encrypted) and allow users to read/write?

Or should I look into creating a rest API that I can use to add/delete/edit records in the database?

Should I even be using SQL for this type of task?

Sorry for all of the questions and just want to make sure I go down the right path, please also note security is very important.

Thanks for your help as always.

Joe

How to Move database files from One location to another in sql2012

$
0
0

I am trying to move my database which is DB1 from its default path to c:\Data folder with its new file name.

alterdatabasedb1

modifyfile(name='db1',

filename='c:\data\newdb1.mdf')

go

alterdatabasedb1

modifyfile(name='db1_log',

filename='c:\data\newdb1log.ldf')

go

it was successfully done but then i could not see the physical files in that location even after refreshing database and in properties dialog box the location was c:\data folder.i was able  open it.

when i restarted my sql service in configuration manager it later showed DB1 with recovery pending..I could not access it.

what has gone wrong ...is there any other method??

Thanx in advance


srm_2010


“The query processor could not start the necessary thread resources for parallel query execution” and “Session Exception: org.hibernate.exception.SQLGrammarException: could not execute query”

$
0
0

One of our spring hibernate application throws exception like “The query processor could not start the necessary thread resources for parallel query execution” and “Session Exception: org.hibernate.exception.SQLGrammarException: could not execute query”.

My server max_workers_count = 576,

8 CPU and total 72GB Ram ,

Cost Thresh hold for parallelism = 30

Max degree of parallelism = 2

My server current_workers_count is only 100 when this exception is thrown.

Is anyone come across this issue then please advise.


logical read vs actual row count

$
0
0

Hi

Can someone tell me what the difference between the logical read from statistics io and the actual row count from actual execution plan.  I have a query that has the following

statistics io
Scan count 1, logical reads 484

actual execution plan
Clustered Index Seek
Actual Row Count : 40067

does this mean that sql has to read 484 pages from disk, and that 484 pages has over 40067 rows?

I wrote my query another way, and numbers becomes

statistics io
Scan count 1, logical reads 1207

actual execution plan
Clustered Index Seek
Actual Row Count : 133

the 1st query took about 2 seconds, but the seconds query took about 4 seconds.  does this mean the logical read is more important

 

thanks

Paul


 

 

SQL Server 2016 Database Engine Tuning Advisor issue

$
0
0

When I run the Turning advisor doesn't matter what database I choose, it never gives me recommendations.

When I look the progress, I see the following

Submitting Configuration Info  - Success

Consuming Workload  - Success

Performing Analysis  - STOPPED

Generating Reports  - STOPPED

Generating Recommendations  - Success

Doesn't matter what database I choose, what query I analysis, all the same.  When I run the same queries in SSMS 2014, they work, but I can't use 2014 to do analysis on 2016 server.

How to generate secure .bak file in SQL Server 2012 Express edition?

$
0
0

As I need took back up the database in a secure way (because its possible to restore the backup database in any other servers). As from this work, I have tried the below scenarios, but I am unable to find the solution.

  1. Transparent based data encryption - only available in Enterprise edition
  2. Password based backup support is deprecated from 2012

I want to make sure that no restore happens without my permission for backup file on any machine then how can I achieve that? 


Trigger between two or more instances

$
0
0

Hello everybody,

I try to create trigger on one table in database after insert, which copy last inserted record to other databases, the same structructre, but other instances. I configured Linked Servers, and it looks ok. But when i try to add record to database trough application, i received error: heterogeneous queries require the ansi_nulls and ansi_warnings options to be set for the connection. Could anybody tell me how to write it??

Viewing all 15264 articles
Browse latest View live


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