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

sp_prepexec results in different and bad execution plan

$
0
0

Hi,

We massively imported 1.5 million rows in a software database table a couple of weeks ago. Since that time, the queries in the search screen perform pourly. I caught those requests and figured out an index that would help them. In my tests the index helped the queries a lot but in the application it didn’t change anything. I found out that the queries, when ran in a sp_prepexec, didn’t use the new index, even if I updated the statistics. What am I missing here?

The queries : 

declare @p1 int
exec sp_prepexec @p1 output,N'@P0 int,@P1 int,@P2 int,@P3 int,@P4 int,@P5 varchar(8000)',N'SELECT COUNT(*) FROM (SELECT TOP (301) 1 as countCol FROM ab_abcontact qRoot WHERE qRoot.Subtype IN (@P0,@P1,@P2,@P3,@P4) AND qRoot.KeywordDenorm LIKE @P5 COLLATE French_CI_AI AND qRoot.StateDenorm = 10063 AND qRoot.CountryDenorm = 10039 AND qRoot.Retired = 0) countTable',5,8,9,11,13,'%fix auto beauport%'
select @p1

Returns in 3975ms.

prepexec plan

SELECT COUNT(*) FROM (SELECT TOP (301) 1 as countCol FROM ab_abcontact qRoot WHERE qRoot.Subtype IN (5,8,9,11,13) AND qRoot.KeywordDenorm LIKE '%fix auto beauport%' COLLATE French_CI_AI AND qRoot.StateDenorm = 10063 AND qRoot.CountryDenorm = 10039 AND qRoot.Retired = 0) countTable;

Returns in 59ms.

direct select

Thanks a lot,

Jean-Michel


Jean-Michel





An error 1069 - )The service did not start due to logon failure) occurred while performing this service operation ...

$
0
0

Hi All,

 

We seem to be being plagued by the error below by our SQL Server agent. This happens almost everytime we restart the server that has been running for a day or two.

 

Our SQL Server Agent uses a none expiring domain credential. I understand that this problem only happens when the profile being used by the SQL Servr Agent has changed (password change). What puzzles me is that the login is A ok and no changes has been made to it's password.

 

We always resolve this problem by changing the login used in the SQL Server Agent to local and after that, returning it back to it's original domain login. Unfortunately, we cant always do this everytime something goes wrong.

 

Can anyone please help us shed a light on this? We're using SQL2k with SP3a. Thanks!

 

Error:

An error 1069 - )The service did not start due to logon failure) occurred while performing this service operation on the SQLServerAgent service.

 

 

Regards,

Joseph

Decimal conversion

$
0
0

Hello all,

drawing a blank here...Monday morning

I have this:

DECLARE @PREWEEK INT = 72159
DECLARE @FIRSTWEEK INT = 70200
SELECT CONVERT(VARCHAR,Abs(100 - ( 100 * CAST( CAST(@PREWEEK AS DECIMAL(12,3)) / CAST(@FIRSTWEEK AS DECIMAL(12,3) ) AS DECIMAL(12,3) ) ) ) )

returns: 2.800

I need it to be 2.80 ...only two decimal places

tried the following and still no go:

SELECT CONVERT(VARCHAR,Abs(100 - ( 100 * CAST( CAST(@PREWEEK AS DECIMAL(12,2)) / CAST(@FIRSTWEEK AS DECIMAL(12,2) ) AS DECIMAL(12,2) ) ) ) )
SELECT CONVERT(VARCHAR,ROUND(Abs(100 - ( 100 * CAST( CAST(@PREWEEK AS DECIMAL(12,3)) / CAST(@FIRSTWEEK AS DECIMAL(12,3) ) AS DECIMAL(12,3) ) ) ),2) )

Thanks

gv


Sword

Database Engine won't start - master DB log file issue

$
0
0

I had a server patched and reboot yesterday and now the SQL services won't start because it's saying it can't find the master log file. I checked the path and the log file is present. Any suggestions.

2014-04-21 09:48:55.22 Server      Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
 Jun 28 2012 08:36:30
 Copyright (c) Microsoft Corporation
 Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1)

2014-04-21 09:48:55.22 Server      (c) Microsoft Corporation.
2014-04-21 09:48:55.22 Server      All rights reserved.
2014-04-21 09:48:55.22 Server      Server process ID is 4008.
2014-04-21 09:48:55.22 Server      System Manufacturer: 'HP', System Model: 'ProLiant DL380 G5'.
2014-04-21 09:48:55.22 Server      Authentication mode is MIXED.
2014-04-21 09:48:55.22 Server      Logging SQL Server messages in file 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\ERRORLOG'.
2014-04-21 09:48:55.22 Server      This instance of SQL Server last reported using a process ID of 4080 at 4/21/2014 9:47:41 AM (local) 4/21/2014 2:47:41 PM (UTC). This is an informational message only; no user action is required.
2014-04-21 09:48:55.22 Server      Registry startup parameters:
  -d C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\master.mdf
  -e C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Log\ERRORLOG
  -l C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mastlog.ldf -g512
2014-04-21 09:48:55.22 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2014-04-21 09:48:55.22 Server      Detected 4 CPUs. This is an informational message; no user action is required.
2014-04-21 09:48:55.33 Server      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.
2014-04-21 09:48:55.35 Server      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.
2014-04-21 09:48:55.38 spid7s      Starting up database 'master'.
2014-04-21 09:48:55.39 spid7s      Error: 17204, Severity: 16, State: 1.
2014-04-21 09:48:55.39 spid7s      FCB::Open failed: Could not open file C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mastlog.ldf -g512 for file number 2.  OS error: 2(The system cannot find the file specified.).
2014-04-21 09:48:55.39 spid7s      Error: 5120, Severity: 16, State: 101.
2014-04-21 09:48:55.39 spid7s      Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\mastlog.ldf -g512". Operating system error 2: "2(The system cannot find the file specified.)".

dm_os_performance_counters not being created for "some" new databases

$
0
0

I have noticed that a couple of our SQL 2008 R2 Ent (10.50.4286) servers are having trouble creating the os performance counters (database level only). I rebooted each of them during a planned downtime and the problem cleared. A few days later I added two new databases to one of the previously affected servers.  Nothing special about either database in fact their just empty shells our development team with populate later.  The first database didn't get any performance counters generated for it.  The second populated just fine.  I confirmed through perfmon that I couldn't find the first database in the list of choices.  I am sure a reboot will probably clear the problem.  However, these are production servers so chances to reboot them only come around once per quarter.  I have run the unload and reload counters command and it had no affect.

Anyone else having this issue?

Problems with backing up to HP 3par disks

$
0
0

Hi,

We have a SQL2012 SP1 build 3412 availability group cluster that recently moved the backend SAN to HP 3par. Since the move we have had the disk array setting changed to high performance for 3par but we still get the errors

The operating system returned the error '59(An unexpected network error occurred.)' while attempting 'SetEndOfFile' and

The operating system returned the error '59(An unexpected network error occurred.)' while attempting 'FlushFileBuffers'.

I have seen http://dirkhondong.wordpress.com/2012/01/27/the-specified-network-name-is-no-longer-available-sql-backup-problem-solved/ as we are using Ola's backup solution. Is changing the registry by creating a DWORD with name ‘Sesstimeout’ and value 360 in HKLM\SYSTEM\CurrentControlSet\Services\lanmanworkstation\parameters the right approach?

Anybody else using HP 3par and having backup troubles?

Thanks

Chris

TempDB size on creation

$
0
0

I've googled this topic to see if TempDB is created based on the model database and get mixed opinions.
Also when I look at model I see the default size is 3MB yet the TempDB initial size is 8MB

My thinking is that 8MB with 10% autogrowth sounds very inefficient and am wanting to increase the file size for tempDB when it is created (after each restart).

Are my feelings warranted? And if so, is it as simple as increasing the size of the model DB?

Excel VBA - SQL Invalid Object Name

$
0
0

I'm running a small piece of SQL code within Excel VBA (no access to SQL Server tools) and am getting "Invalid object name 'LoanSummary'" error.  I know for a fact that LoanSummary is a valid name of a table within the database.  What could be wrong???  I've written similar code for different tables and no problem.  I've tried adding MyDB.dbo to the table name, but no luck. Any thoughts would be greatly appreciated.

BELOW IS MY CODE:

Sub GetDataTest()

'Declare variables'
Set objMyConn = New ADODB.Connection
Set objMyRecordset = New ADODB.Recordset
Dim strSQL As String

MyLoan = 123456

'Open Connection'
objMyConn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=FMC\reports;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=SECONDARYTS;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=MyDB"
objMyConn.Open

'Set and Excecute SQL Command'
strSQL = "SELECT LoanSummary.[LoanNumber] FROM LoanSummary WHERE LoanSummary.[LoanNumber]=LTRIM(STR(" & MyLoan & "));"

'Open Recordset'
Set objMyRecordset.ActiveConnection = objMyConn
objMyRecordset.Open strSQL   '<----- ERROR HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

'if EOF = true, then the loan wasn't found
If objMyRecordset.EOF = True Then
    objMyConn.Close
    Set objMyRecordset = Nothing
    Set objMyConn = Nothing
    Exit Sub
End If
'Copy Data to Excel'
ActiveSheet.Range("A1").CopyFromRecordset (objMyRecordset)

objMyConn.Close
Set objMyRecordset = Nothing
Set objMyConn = Nothing

End Sub


Allocating Processor.

$
0
0

Hi,

Want to restrict the SQL Server to the limit of single processor when the server has 2 processors. ( Without Resource Governor )

Captured below details using dxdiag

Processor: Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz (16 CPUs), ~2.4GHz (2 Processors)

Pls suggest.

Thanks,

Mohanraj


I want to give a user to read only rights on sql server agent 2008

$
0
0

I want to give a user to read only rights on sql server agent 2008.When I giving SQLAgentuser Role then user is only able to view SQL Server agent as Green but no job visible in job activity monitor.Currently he has db_reader rights on one user database.

What rights should I give?


Thanks

Read Only db after attach on sql 2008

$
0
0

Hi,

i have detach db from sql 2008 for some reason.

i attached the db again. now it shows read-only.

can anyone let me know why it shows read only?

how can fix this ?

Thanks!!!

 


Varinder Sandhu http://varindersandhus.blogspot.com/

backup history all servers

$
0
0

I'd like to write a report with backup history for all sql servers. I can manually easily get it by using registered servers and running a single query on all of them (I have the query, I just don't know how to gather a single resultset for multiple servers).

I wanted to avoid openquery or linked servers. Is there any best way of getting this done? SSIS package seems involved. Is there a magic powershell? thanks!


Paula

How can Database A on Server A be available as Database B

$
0
0
SQL Server 2012 Enterprise on Windows Server 2012 R2 DataCenter - VMWare Server

Question:
Can Database A on Server A be available as Database B (within 10 minutes of data time difference) on Server A (same server) for reporting.

Possible Answers:
1. Transactional Replication - Yes 
2. Log Shipping - No, because Database will not be available as Read Only or if available for  read only, will kick out active connections when logs are applied on reporting database
3. Always On Availability Groups - No, because the reporting database needs to be on another server. 
4. Mirroring - No, because this feature is being deprecated
5. Clustering Active/Active - No, because the reporting database needs to be on another server. 

It appears as though transactional replication is the only option. 

Please guide if there are other options. 

Thank you. 

-Jeelani

Best way to remove a data file from a database

$
0
0

Best way to remove a data file from a database? The primary data file can't be removed and the other files are all in the same filegroup. Is there a best way to remove a data file? Thank you


Paula

Querying dm_resource_governor_resource_pools gives different results depending on who is logged in.

$
0
0

For example pool1 has active memgrant count = 1 when i run the query. when sa runs the query the value is 0.

How can I troubleshoot?

EDIT - problem solved the active memgrant count was including the spid used to query the dmv (itself), when running from a different log in in a different pool if was correctly showing 0.

Database files list on one drive in master.sys.master_files, but show on another in the file system

$
0
0

We have a one node cluster sql server instance where the machine was patched/updated and re-booted this past weekend.  The machine came up, but the SQL Server did not because it could not locate RestoreCheckpointDB24.ckp on anM drive.  If I RESTOREFILELISTONLY on my backups everything was clearly on an N drive previously.  To get by the error, our network team changed a registry key pointing toN drive to M drive and everything magically came up.  The file system and failover cluster manager are now showing all files to be on anM drive, but if you query master.sys.master_files everything is showing on theN drive.  Anyone know how this is possible and how to resolve???

As well, a log shipping session is now broken because it's copying to a missingN drive and my Management->SQL Server Logs folder is empty as well. 

Any ideas?  I'm completely baffled as well as our network guys. 

Thanks!

Cannot drop a login because the user is logged on

$
0
0

I want to be able to drop a login forcefully even if the login is currently logged on, its a SQL login. I have tried setting the database offline and online but that does not seem to do the trick, the way I do this is to restart the SQL service, but this often require logging onto the server to do this, I was wondering whether there are other options other than restarting the service.

If I disable the login, the login is still connected because the connection persists from the application unless SQL is restarted or unless the application is restarted.

Any ideas ?

SQL Server Transaction log corruption

$
0
0

Hi,

I have a strange problem in one of the SQL 2012 SP1 database. Sometimes my transaction log file grow unexpectedly than the preallocated space and i had to shrink it back . I usually preallocate space to around 15GB and the autogrow is set to 1000MB. The VLF count is less than 50. Database recovery model is Simple.

After i shrink the file and preallocate space again,everything seems to be normal.But later when the backup starts, SQL server starts generating the below error. The database will remain online and accept connections. Users do not get any errors or disconnected. The logs continue to grow as it cannot issue a checkpoint. We resolve this error by restarting SQL as database goes through crash recovery and comes up clean. Checkdb does not show any data corruption as well. I am not sure why the log gets corrupted after the shrink operation. Can someone please advice.

"The log scan number (10082614:43271:1) passed to log scan in database 'xyz' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup."

"One or more recovery units belonging to database 'xyz' failed to generate a checkpoint. This is typically caused by lack of system resources such as disk or memory, or in some cases due to database corruption. Examine previous entries in the error log for more detailed information on this failure."

Thanks

resilient file system on SQL 2014

$
0
0
 I know that you were not able able to run SQL 2012 with ReFS.   It seems that this has been fix with SQL 2014.   Is it still recommend to use NTFS or can the SQL Engine & databases now reside on a ReFS Volume?  Is there a major difference in IOPS numbers when used by SQL ?

difference between "print" statements and "select" statements , TSQL

$
0
0

 

What is the difference between "print" statements and "select" statements when it omces to debugging and watching varibles in the stored procs .....
Viewing all 6624 articles
Browse latest View live