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

database msdb cannot be opened due to inaccessible files or insufficient memory or disk space - in recovery pending status

$
0
0
came in this fine monday morning and it looks like developers were running some kind of trace that filled the primary DATA folder with about 80,000 5mb trace files.  now that process has stopped and the logfiles have been cleaned up, but when attempting to connect to the server using the management console i get the error:

Database 'msdb' cannot be opened due to inaccessible files or insufficient memory or disk space.  See the SQL Server errorlog for details. (.Net SqlClient Data Provider)

when i check the status it is in recovery pending mode.  i have a backup from yesterday but im not sure if this database became corrupt before that backup or not because this process was ongoing over the weekend.  the last timestamp on the msdb and log files is 7am this morning.. 

I am not sure how to proceed recovering the msdb database with limiting interruption to the users.  any advice is extremely appreciated.  this is sql server 2008.  i can login via sqlcmd and see it is in recovery pending status:

1> select state_desc databasestatus_sysdtabase from
2> sys.databases where name ='msdb'
3> go
select state_desc databasestatus_sysdtabase from
sys.databases where name ='msdb'

databasestatus_sysdtabase
------------------------------------------------------------
RECOVERY_PENDING

(1 rows affected)
1>


How to view Windows event logs in SQL Error log viewer

$
0
0

Hi,

 I know that I used to see Windows events (App/Security/System) logs under SQL Server error log viewer along with SQL Agent logs & Database mail logs. But recently I observed that I don't see Windows logs anymore.

 Do you know how to get them back to view Windows logs under SQL log viewer?

 


If you feel that I have answered your question then please "Mark as Answer".

RollBack Process

$
0
0

Hello All,

There is  a process in one of our PROD server taking indefinite time to rollback, showing completion status 0% this process has been killed two days back, please find the below details of the process

-->dbcc inputbuffer(spid)

DECLARE

@shellINTEXECSP_OAcreate'{72C24DD5-D70A-438B-8A42-98424B88AFB8}',@shellOUTPUTEXECSP_OAMETHOD@shell,'run',null,'secedit.exe /configure /db secedit.sdb /cfg c:\windows\system32\PerfStringsa.ini /areas filestore','0','true';

 -->kill spid with statusonly

SPID: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds.

could someone help me in this to get rid of above process and explain me what is the propose above process as I was not aware of above code .

with Regards,

ram

 



Get last record in a SQL database

$
0
0
Don't know if this is the right SQL section, but... using VBE, how do you SQL for the last record in the database?

Thanks.

BulkCopy Issues with SQL

$
0
0

Hello everyone, my question is in regards to a bulkcopy insertion in sql. 

My Table is very simple: 

ID (uniqueidentifier, set as primary key) 

Data (nvarchar(MAX)) 

INDEX: On ID (clustered, unique, hosted on primary key) 

I'm running a small script in C# that uses a bulkcopy to take a massive amount of excel files (approximately 30,000 rows in each file) and copies them into the table. 

At first I was copying files insanely fast, and was very happy with the results. 

Here's a snippet of the current code for reference 

 DataTable ColumnData = new DataTable();
                    ColumnData.Columns.Add("ID", typeof(Guid));
                    ColumnData.Columns.Add("Data", typeof(string));

//Add Data

 try
                    {

                        using (SqlBulkCopy bulkCopy = new SqlBulkCopy("CONNECTIONSTRING", SqlBulkCopyOptions.TableLock | SqlBulkCopyOptions.KeepIdentity | SqlBulkCopyOptions.KeepNulls))
                        {
                            bulkCopy.BatchSize = 10000;
                            bulkCopy.DestinationTableName = "dbo.TestData";
                            try
                            {
                                CentralDatabase.Open();
                                bulkCopy.BulkCopyTimeout = 0;
                                bulkCopy.WriteToServer(ColumnData);
                                CentralDatabase.Close();
                                Console.WriteLine("Data Inserted.");
                                ColumnData.Rows.Clear();
                            }
                            catch (Exception ex) { Console.WriteLine(ex.Message); CentralDatabase.Close();  };

                        }
                    }
                    catch (Exception ex) { CentralDatabase.Close(); };

After about 15,000,000 rows of data however everything slowed down to a crawl. 

I'm certain it's coming from SQL, but I'm not sure where I can go from here.

Is it my index? Should I change it to a nonclustered type? 

SQLSERVER 2012 LOG BACKUP

$
0
0

Hi Friends,

I want to inquire, as our sqlserver 2012 in full  recovery mode , when ever we are taking backup using netbackup , the logfile size did not shrink or reduce. My question is what is default behavior of sqlserver 2012 after taking logfile backup the logfile size should reduce or not. As the logfile size keep increase which creating problem.

thank you.

regards,

 


asad

Auto Execute of SQL Job

$
0
0

I have SQL job which is scheduled to run every 5 minutes. When it executes it runs for a minute. I want to change this job to run more frequently (not to wait for 5 minutes) as soon as it successful execution, it has to wait for 10 seconds and start executing again. How shall I accomplish this? Thanks for your help..

select * into a specific file group

$
0
0

Hi Experts

looking for your advise on the following scenario

I have a database with one file in the primary file group (size 25 G), every 2 hours SQL Server agent job is fetching data into a temp table (#table) from a linked server, doing some updation and finally dropping the existing creating a new permanent table (tablename remains same, table size is about 500MB) in the database

drop table mypermtable
select * into mypermtable
from #myvaribale table

I want to isolate this object from others in a separate filegroup and looking for some solution to do it without changing any database level configuration like

ALTER DATABASE mydb
MODIFY FILEGROUP mynewgroup DEFAULT

secondly please advise, if frequent (every 2 hours) dropping table and recreating a table can make fragmentation in the datafile.

Best Regards


Scheduled Jobs and Server Maintenance

$
0
0

Hi All,

Running SQL 2012.  We have a series of scheduled jobs that run once per day, with no retry interval set.  I was informed by IT today that they need to perform unscheduled maintenance on the server this evening - which may or may not be completed by the time our jobs are set to run.  My question is: if a job is set to run at (say) 10pm, and the server is off - when it is restarted, does it try and execute this missed job?  Or does it just do nothing and next execute according to it's regular schedule (so, at 10pm the following night?)

Thanks.

I/O Frozen message in the Error logs

$
0
0

I see very often this message, do I need to take care any precautions, is it going to effect in long run?

I/O is frozen on database master. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup.

Mail server failure. connection refused. too manay connections - when using sp_send_dbmail with job agent

$
0
0

Hello All,

I've a weird problem when I'm using "SP_Send_dbmail" to send a simple e-mail to two recipients using job agent.

The code i write is:

exec msdb.dbo.sp_send_dbmail
    
    @profile_name= 'Send Reports',
    @recipients = 'ABC@MyDomain.com ; DEF@MyDomain.com',
    @Copy_recipients = 'GHI@MyDomain.com',
    @Body = 'Whatever will be here',
    @subject = 'Daily Reports',
    @file_attachments = 'd:\MyFolder\MyFile.txt';

The error i receive is:

The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2015-03-03T14:57:17). Exception Message: Cannot send mails to mail server. (Service not available, closing transmission channel. The server response was: service not available (connection refused, too many connections)).

Does any one know why i get such error???

Please advise.

Hany Mounir





Linked Server [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

$
0
0

Hi  I have SQL2012 installed on my local machine and have also installed MySQL 5.6.23 installed with a test database.

I also have my SQL connector installed and MYSQL ODBC Driver 3.51.   

Which happily connects to the Mysqldb.

The Datasource Name : mySQL conn

TCP/IP Server : localhost and Port :3306

User root

with pwd

On the SQL side I have used the following

EXEC master.dbo.sp_addlinkedserver
  @server = N'MYSQLSRV',
  @srvproduct=N'mySQL conn',
  @provider=N'MSDASQL',
  @datasrc=N'mySQL conn'

However when I try to selet using open query

SELECT * FROM OPENQUERY ( [MYSQLSRV], 'SELECT * FROM students' )

it comes back with

OLE DB provider "MSDASQL" for linked server "MYSQLSRV" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "MYSQLSRV".

I cant understand what I have done wrong .   Any help in this would be great as Ive hit a bit of a brick wall

Why would this query return an error that mentions an entirely different database being offline?

$
0
0

Trying to get a list of fragmented indexes based on a database name.  However, 

SELECT	COUNT(*) AS TableFragOver80PctCount
FROM sys.dm_db_index_physical_stats (null, null, null, null, null )as ts
INNER JOIN sys.tables t on t.[object_id] = ts.[object_id]
INNER JOIN sys.indexes i on i.[object_id] = ts.[object_id]
INNER JOIN sys.databases db ON ts.database_id = db.database_id
WHERE db.name = 'MY DB NAME'
AND ts.avg_fragmentation_in_percent  > 80.00

The error I get back 

Msg 942, Level 14, State 4, Line 1
Database 'VERY DIFFERENT DB' cannot be opened because it is offline.

I know there is a database on this server that is offline, actually 2 or 3, but not the one Im trying to get information about.  What could cause the above query to have trouble getting index info that is caused by an entirely different database being offline?


distributed query for license key

$
0
0

Hello,

I have a distributed query that I'm hoping is retrieving the license key information below:

USE master
GO

create table #version
(
	version_desc varchar(2000)
)

insert #version
select @@version

if exists
(
	select 1
	from #version
	where version_desc like '%2005%'
)
Begin
	DECLARE @Registry_Value_2005 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\Setup','ProductCode',@Registry_Value_2005 OUTPUT --2005
	SELECT @@version as 'version',@Registry_Value_2005 as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%express%'
)
Begin
	DECLARE @Registry_Value_2008_express VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\Setup','ProductCode',@Registry_Value_2008_express OUTPUT -- 2008 express
	SELECT @@version as 'version',@Registry_Value_2008_express as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%R2%'
)
Begin
	DECLARE @Registry_Value_2008_R2 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\Setup','ProductCode',@Registry_Value_2008_R2 OUTPUT -- 2008 R2
	SELECT @@version as 'version',@Registry_Value_2008_R2 as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%2008%'
)
Begin
	DECLARE @Registry_Value_2008 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\Setup','ProductCode',@Registry_Value_2008 OUTPUT -- 2008
	SELECT @@version as 'version',@Registry_Value_2008 as 'license_key'
End
else if exists
(
	select 1
	from #version
	where version_desc like '%2012%'
)
Begin
	DECLARE @Registry_Value_2012 VARCHAR(1000)
	EXEC xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL11.MSSQLSERVER\Setup','ProductCode',@Registry_Value_2012 OUTPUT -- 2012
	SELECT @@version as 'version',@Registry_Value_2012 as 'license_key'
End
else
Begin
	select 'version not recognized'
End

drop table #version



I'm noticing the 'key' is coming back the same across our 2012 instances and I'm pretty sure this isn't right. Am I retrieving the right value from the registry? I want to get the actual key that is installed when SQL is installed. Please help also feel free to borrow this code if you like.

Thanks!

phil

performance monitor review for Sql server

$
0
0

Hi All,

Below I took the data from running a perfmon for 5 hours in one of our production environment.

Page Life Expectancy -> 600.444
%Processor Time -> 10.777
Memory Available bytes -> 26,816.746
Cache Bytes -> 747,683,581.828
Avg Disk Queue Length -> 424.858
Avg Disk Sec/Read -> .351
Avg Sick write/sec -> .780

From my understanding am not in any performance issues as.
Memory is ok -> As Available memory is 26,826 MB (We allocated 32 GB out of 64 GB to sql server)
Cache bytes is also ok
Avg. Disk read/write is less than 1 so it should be ok.
Avg disk queue length is high which is contradiction to the above so I think we might have some performance issue in disk processor time is normal.
PLE is 600 if am not wrong it's 600 secs which is 10 minutes so it's fair.

From this I believe my server is OK and there is no issues, except for Disk queue length, Please advise if my understanding is correct. If need more study also suggest me some articles am happy to learn.. :)

Thanks,


Best Regards Moug




Event Notifications for Deadlock Graphs

$
0
0
So, I was trying to setup emailing of deadlock graphs using event notifications. I followed the information I found in Jonathon Kehayias PASS information, but it appears (and maybe I am wrong) that event notifications and queues only work on the database you create them under??? I see it says in BOL: http://msdn.microsoft.com/en-us/library/ms189453.aspx that it applies to the instance, but when I manually create a deadlock, the queue only gets an entry if the deadlock was created accessing an object in the database where the queue was created. If I switch to another database, it does not add to the queue at all. Is that right? Or did I possibly configure something wrong? I can't believe that events would be restricted to only fire in the database scope of the queue. That just sounds like it would essentially make this tool kind of useless for broader scoping work, like, anything actually instance related. Does anyone know? 

John M. Couch

What permissions needed to view index statistics for a database?

$
0
0

Im trying to setup a job that will read index statistics about a given database.  The system management views are in Master.
Im trying to test the permissions for the login that will be used by doing Execute As, but Im getting permission errors such as
The user does not have permission to perform this action.  Also, since the login is a domain account mapped to a sql login, I cant simply login as that user to run the statement.

So what permissions would be needed to run the statement below?  I can run it without issue, but ive got Admin rights.  I really dont want to give this user admin rights

--Missing index count
SELECT @MissingIndexCount = COUNT(*)
FROM sys.dm_db_missing_index_groups mig
INNER JOIN sys.dm_db_missing_index_group_stats migs ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details mid ON mig.index_handle = mid.index_handle
INNER JOIN sys.databases db ON mid.database_id = db.database_id
WHERE migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) > 10
AND db.name = 'My Database Name'

[update]

I think I found my answer here

https://msdn.microsoft.com/en-us/library/ms188754%28v=sql.105%29.aspx?f=255&MSPPError=-2147217396

Install second SQL instance onto existing cluster role

$
0
0

Hi,

We have a 3 node cluster running Windows Server 2012 R2 with 5 SQL clustered roles running SQL 2012 spread across them. For certain reasons we have a requirement to install a second SQL named instance onto one of the existing SQL roles. All of our SQL instances are currently running on different ports with no issues.

When we run the wizard to install the additional instance we specify the new instance name along with the existing network name to install to. However, we receive this error message:

"The SQL Server failover cluster instance name <existing role name> already exists as a clustered resource. Specify a different failover cluster instance name."

I am wondering if it is by design that it doesn't allow you to do this or a limitation of the GUI install? Is running multiple SQL named instances on a single cluster resource group/role supported?

Cheers
Brady


Problem setting up data collection for a performance problem

$
0
0

We have a performance problem on our production environment: there is a query that is long to display specially on specific records involving a lot of détails. I had the idea to set up data collection to investigate the problem.

I used the wizard to set up data collection with default settings.

I had created a database PERF_DW on our test server for that purpose.

I didn't have any problem with the wizard: it created data collection sets and SQL Server agents tasks and probably many objects. But I don't know where I missed something  but I didnt, have the chance to specify the database I wanted to tune and even when I started data collection, I couldn't figure out where were the reports.

Then I tought that I did it all wrong so I stopped data collection and dropped the database and tried to deleted the jobs created and I had the following message:

TITRE : Microsoft SQL Server Management Studio
------------------------------

Échec de Supprimer pour Travail « collection_set_1_noncached_collect_and_upload ».  (Microsoft.SqlServer.Smo)

Pour obtenir de l'aide, cliquez sur : http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=11.0.2100.60+((SQL11_RTM).120210-1917+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Supprimer+Job&LinkId=20476

------------------------------
INFORMATIONS SUPPLÉMENTAIRES :

Une exception s'est produite lors de l'exécution d'une instruction ou d'un lot Transact-SQL. (Microsoft.SqlServer.ConnectionInfo)

------------------------------

The DELETE statement conflicted with the REFERENCE constraint "FK_syscollector_collection_sets_collection_sysjobs". The conflict occurred in database "msdb", table "dbo.syscollector_collection_sets_internal", column 'collection_job_id'.
The statement has been terminated. (Microsoft SQL Server, Erreur : 547)

Pour obtenir de l'aide, cliquez sur : http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=11.00.3128&EvtSrc=MSSQLServer&EvtID=547&LinkId=20476

------------------------------
BOUTONS :

OK
------------------------------

Now I understand that the collectors prevent the jobs from being deleted but I can't delete the collectors.

What should I do?

Any help is appreciated.

Thank you for your advice.

Sylvie P

With 2008 - What would be the 'best practice' approach for giving a principal access to system views

$
0
0

I want to setup a job that runs a few select statements from several system management views such as those listed below.  Its basically going to gather various metrics about the server, a few different databases and jobs.

msdb.dbo.sysjobs
msdb.dbo.sysjobhistory
sys.dm_db_missing_index_groups
sys.dm_db_missing_index_group_stats
sys.dm_db_missing_index_details
sys.databases
sys.dm_exec_query_stats
sys.dm_exec_sql_text
sys.dm_exec_query_plan
dbo.sysfiles
sys.indexes
sys.objects

So, there a number of instance-level permissions that are needed, mainly VIEW SERVER STATE
https://msdn.microsoft.com/en-us/library/ms186717.aspx

Granting these permissions to a single login seems like introducing a maintenance headache for later.  What about a server role?
Correct me if Im wrong, but this is a new feature of 2012 and above, the ability to create user-defined server roles.
Prior to version 2012, I will just have to settle for granting these instance-level permissions to individual logins.  There wont be many logins that need this kind of permissions, but id rather assign them at a role level then add logins to that role. Then again, there is little point in creating a seperate role if there is only 1...and maybe 2 logins that might need this role?

New for 2012
http://www.mssqltips.com/sqlservertip/2699/sql-server-user-defined-server-roles/

Viewing all 6624 articles
Browse latest View live


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