Ads

17 November 2011

Script to identify DeadLock -Longtime_Query

select s.session_id, s.login_time, s.login_name
, s.host_name, s.program_name, s.last_request_end_time
, r.start_time, r.command, r.open_transaction_count
, SUBSTRING(st.text, (r.statement_start_offset/2)+1,
((CASE r.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE r.statement_end_offset
END - r.statement_start_offset)/2) + 1) as statement_text
, coalesce(QUOTENAME(DB_NAME(st.dbid)) + N'.'
+ QUOTENAME(OBJECT_SCHEMA_NAME(st.objectid, st.dbid)) + N'.'
+ QUOTENAME(OBJECT_NAME(st.objectid, st.dbid))

, '') as command_text
from sys.dm_exec_sessions as s
join sys.dm_exec_requests as r
on r.session_id = s.session_id
cross apply sys.dm_exec_sql_text(r.sql_handle) as st

order by s.last_request_end_time;

Script to script out logins and permissions

--select * from master.DBO.TEMP_TABLE_FOR_USERS
DECLARE @DBNAME VARCHAR(50),
@STORAGEDBNAME VARCHAR(50)
SET @DBNAME='ReportingDatabase'
SET @STORAGEDBNAME='master'

SET NOCOUNT ON
DECLARE @CMD VARCHAR(350)
SET @CMD= 'IF  EXISTS (SELECT * FROM '+@STORAGEDBNAME+'.sys.objects WHERE object_id = OBJECT_ID('''+@STORAGEDBNAME+'.[dbo].[TEMP_TABLE_FOR_USERS]'')
AND type in (''U''))
DROP TABLE '+@STORAGEDBNAME+'.DBO.TEMP_TABLE_FOR_USERS
CREATE TABLE '+@STORAGEDBNAME+'.DBO.TEMP_TABLE_FOR_USERS
([COMMAND] TEXT)'

EXEC (@CMD)
CREATE TABLE #TEMP
(   NUMBER INT IDENTITY(1,1) NOT NULL,
USERNAME VARCHAR(100),
ROLENAME VARCHAR(100)
)
CREATE TABLE #TEMP1
(   NUMBER INT IDENTITY(1,1) NOT NULL,
OBJECTNAME VARCHAR(100),
TYPE_DESC VARCHAR(100),
PERMISSION_NAME VARCHAR(100),
STATE_DESC VARCHAR(100),
USERNAME VARCHAR(100)
)
CREATE TABLE #TEMP2
(   NUMBER INT IDENTITY(1,1) NOT NULL,
USERNAME VARCHAR(100)
)

DECLARE @CMD1 VARCHAR(500),
@USER INT,
@USERNAME VARCHAR(50)

SET @CMD1= 'SELECT U.NAME , G.NAME
            FROM '+ @DBNAME+'.DBO.SYSUSERS U,' +@DBNAME+'.DBO.SYSUSERS G,' +@DBNAME+'.DBO.SYSMEMBERS M
            WHERE   G.UID = M.GROUPUID
            AND G.ISSQLROLE = 1 AND U.UID = M.MEMBERUID AND U.NAME<>''dbo'''
INSERT INTO #TEMP
EXEC (@CMD1)

INSERT INTO #TEMP2
SELECT DISTINCT USERNAME FROM #TEMP
DECLARE @CMD2 VARCHAR(5000)
SET @CMD2= 'DECLARE @COUNT INT,@USER INT
SET @COUNT=1 SELECT @USER=COUNT(*) FROM #TEMP2 WHILE @USER>=@COUNT
BEGIN
INSERT INTO '+@STORAGEDBNAME+'.DBO.TEMP_TABLE_FOR_USERS
SELECT ''IF NOT EXISTS (SELECT * FROM SYS.DATABASE_PRINCIPALS WHERE NAME = ''''''+USERNAME+'''''')
CREATE USER [''+USERNAME+''] FOR LOGIN ['' +USERNAME +''] WITH DEFAULT_SCHEMA=[DBO]'' FROM #TEMP2
WHERE NUMBER=@COUNT SET @COUNT=@COUNT+1
END'
EXEC (@CMD2)
-------------------- Schema Starts Here ------------------

CREATE TABLE #TEMP3
(   NUMBER INT IDENTITY(1,1) NOT NULL,
SCHEMANAME VARCHAR(100)
)
INSERT INTO #TEMP3 SELECT NAME FROM SYS.SCHEMAS WHERE [SCHEMA_ID] BETWEEN 5 AND 16383


DECLARE @CMD5 VARCHAR(5000)
SET @CMD5= 'DECLARE @SCHEMA INT,
@COUNT3 INT
SET @COUNT3=1
SELECT @SCHEMA=COUNT(SCHEMANAME) FROM #TEMP3
WHILE @SCHEMA>=@COUNT3
BEGIN
INSERT INTO '+@STORAGEDBNAME+'.DBO.TEMP_TABLE_FOR_USERS
SELECT ''IF NOT EXISTS (SELECT * FROM SYS.SCHEMAS WHERE NAME = ''''''+SCHEMANAME+'''''')
EXEC SYS.SP_EXECUTESQL N''''CREATE SCHEMA [''+SCHEMANAME+''] AUTHORIZATION ['' +SCHEMANAME +'']'''''' FROM #TEMP3
WHERE NUMBER=@COUNT3 SET @COUNT3=@COUNT3+1
END'


EXEC (@CMD5)

-------------------- User Role Starts Here ---------------
DECLARE @CMD3 VARCHAR(5000)
SET @CMD3= 'DECLARE @ROLE INT,
@COUNT2 INT
SET @COUNT2=1
SELECT @ROLE=COUNT(ROLENAME) FROM #TEMP
WHILE @ROLE>=@COUNT2
BEGIN
INSERT INTO '+@STORAGEDBNAME+'.DBO.TEMP_TABLE_FOR_USERS SELECT ''EXEC sp_addrolemember ''''''+ROLENAME+ '''''' ,''''''+ USERNAME+'''''''' FROM #TEMP
WHERE NUMBER=@COUNT2 SET @COUNT2=@COUNT2+1
END'

EXEC (@CMD3)

--------------------- Secure Permission Starts Here ---------------
INSERT INTO #TEMP1
SELECT O.NAME COLLATE LATIN1_GENERAL_CI_AS_KS_WS AS OBJECTNAME ,TYPE_DESC,
PERMISSION_NAME,STATE_DESC,U.NAME AS USERNAME
FROM SYS.DATABASE_PERMISSIONS P
INNER JOIN SYS.OBJECTS O ON O.OBJECT_ID=MAJOR_ID
INNER JOIN SYSUSERS U ON U.UID=P.GRANTEE_PRINCIPAL_ID

DECLARE @CMD4 VARCHAR(5000)
SET @CMD4= 'DECLARE @SECUR INT,
@COUNT1 INT
SET @COUNT1=1
SELECT @SECUR=COUNT(*) FROM #TEMP1
WHILE @SECUR>=@COUNT1
BEGIN
INSERT INTO '+@STORAGEDBNAME+'.DBO.TEMP_TABLE_FOR_USERS SELECT ''''+STATE_DESC+'' ''+PERMISSION_NAME+'' ON ''+OBJECTNAME+''  TO [''+USERNAME +'']''FROM #TEMP1
WHERE NUMBER=@COUNT1 SET @COUNT1=@COUNT1+1
END'
EXEC (@CMD4)

-------------------- Final Output ---------------
DROP TABLE #TEMP
DROP TABLE #TEMP1
DROP TABLE #TEMP2
DROP TABLE #TEMP3
SET NOCOUNT OFF

SQL Agent Script

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
ExecNotificationQuery("select * from __instancedeletionevent " _
& "within 1 where TargetInstance isa 'Win32_Process'")
Do While i = 0
Set objLatestProcess = colMonitoredProcesses.NextEvent
If objLatestProcess.TargetInstance.Name = "sqlservr.exe" Then
Set objEmail = CreateObject("CDO.Message")
SmtpMail.SmtpServer = "indblrvmsg00"
objEmail.From = "Test@aditi.com"
objEmail.To = "pradyothanapd@aditi.com"
objEmail.Subject = "SQl Server is down on" & strcomputer
objEmail.Textbody = "SQL Sever is down"
objEmail.Send
End If
Loop

16 November 2011

The transaction log for database DBNAME is full

ERROR :-

Msg 9002, Level 17, State 2, Line 4
The transaction log for database DBNAME is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases


http://sqlskills.com/BLOGS/PAUL/post/Search-Engine-QA-1-Running-out-of-transaction-log-space.aspx

15 November 2011

SSIS Deployment Issue - In cluster Environment





Resolution OR Workaround
-------------------------------
SSIS is not a part of cluster service, Its an individual component and server name in the xml will refer to default or local instance by .(DOT). This we need to change as SQL Server will be on a cluster with a VIRTUAL NAME.


1. Stop the SSIS Service
2. Open up MsDtsSrvr.ini.xml file which is available in "C:\Program Files\Microsoft SQL Server\100\DTS\Binn\” folder
3. Replace the Server Name node with Clustered Instance Name (replace “.” With cluster instance name)
4. Restart the SSIS Service


This will resolve the issue.Good Luck.


Note :- Will get error if we dint restart the SSIS services.


11 November 2011

Setup SSRS in SharePoint Integrated Mode

This post is about configuring SQL Server Reporting Services in SharePoint Integrated mode the quick and clean way with no fuzz in 40 steps.

I'm not discussing the default values, I will only talk about the values which need to be changed or selected in order to get SSRS set up in the least amount of steps.


The scenario:
SharePoint 2010 Enterprise Edition + named instance SQL Server 2008 Express Edition which is deployed during the SharePoint setup. Name of the SQL Server instance: SHAREPOINT.
Separate default SQL Server 2008 R2 instance (Enterprise Edition).
SSRS currently installed in native mode on the SQL Server 2008 R2 default instance.
AdventureWorksDW2008R2 hosted on the SQL Server 2008 R2 default instance.
The procedure contains 5 parts:

A. SSRS Configuration {SQL Server}
B. Web application {SharePoint}
C. Site collection {SharePoint}
D. SSRS integration {SharePoint}
E. Content types {SharePoint}
Let's start!

A. SSRS Configuration {SQL Server}
Log on to your SharePoint 2010 box.
Fire up the SQL Server Reporting Services Configuration Manager.
Connect to the Report Server instance. In my case this is the default SQL Server 2008 R2 instance (MSSQLSERVER)
The first thing you will notice is the Report Server Status. Check the Report Server Mode. It should say Native (we start from native mode in this scenario).
Click Database in the left pane.Click Change Database. Select Create a new report server database.
Enter the proper credentials.
Enter a database name and select SharePoint Integrated mode.
Enter the credentials and do not forget the \ (.\ will do as well).
Choose Report Manager URL in the left pane and click the apply button. This will configure the Report Manager virtual directory.
Backup the encryption keys.

B. Web application {SharePoint}
Open the SharePoint Central Administration website.
Choose Application Management > Manage web applications.
Click the New button in the ribbon. This will bring up the Create new web application popup.
Keep the default values to keep things simple except for:
Choose a name for the new IIS Website. I will choose SSRSDemo in this example.
Choose a name for the application pool. I will again choose SSRSDemo.
Make sure you connect to the right database instance. In my example I will connect to the named SQL Server 2008 Express Edition instance named SHAREPOINT.
Choose a database name or keep the default value with the GUID suffix. I will call the database WSS_Content_SSRSDemo.
Hold your horses before you hit the OK button when this information pops up:
The Microsoft SharePoint Foundation Web application has been created.

If this is the first time that you have used this application pool with a SharePoint Web application, you must wait until the Internet Information Services (IIS) Web site has been created on all servers. By default, no new SharePoint site collections are created with the Web application. If you have just created a Forms Based Authentication (FBA) Web application, then before creating a new site collection, you will need to perform some additional configuration steps.

Learn about how to configure a Web application for FBA.

Once you are finished, to create a new site collection, go to the Create Site Collection page.


5. Click Create Site Collection page to move on to C. Site collection {SharePoint}


C. Site collection {SharePoint}
Enter a title for the site collection. SSRSDemo for example.
Choose a template. I will choose Business Intelligence Center because I want to store my SSRS reports in a BI related environment.
Enter a username for Primary Collection Administrator. Make sure you enter the full domain name. e.g.: \ (.\username won't work here).
D. SSRS integration {SharePoint}

Go to the SharePoint Central Administration website > General Application Settings > Reporting Services > Reporting Services Integration.
Enter the Report Server Web Service URL which you can find the SQL Server Reporting Services Configuration Manager.
Choose the Authentication Mode. I will choose Windows Authentication. Entering .\ will do.
Go to the SharePoint Central Administration website > General Application Settings > Reporting Services > Add a Report Server to the Integration.
The server name should already be provided and enter the name of the SQL Server instance which hosts the report server database.
Enter the credentials.

E. Upload a report {SharePoint}
Open your new top level web site we created in C. Site collection {SharePoint}
In case you forgot the URL of the web site, go to SharePoint Central Administration > Web Application and look for the URL.
Go to All site Content > Documents.
In the ribbon, go to Library Tools > Library.
Click Library Settings.
Click Advanced Settings.
In Content Types, check Yes for Allow Management of content types and click OK.
In the columns section, click Add from existing site columns.
In the Select site columns from drop-down box, select Report Server Content Types.
Select all available site content types and click the Add button followed by OK.
Go back to All site content > Documents.
Click the Add Document link.
Browse for a Report provided by the AdventureWorksDW200R2 samples from CodePlex.
Enter a title for the report.

More Information on :-
-------------------------------
http://sqlug.be/blogs/steves_sql_blog/archive/2011/04/05/setup-ssrs-in-sharepoint-integrated-mode.aspx
------------------------------

08 November 2011

NO Start Button,, Need Manage Server ..Here you go

Manage Windows Server 2008 R2 Core with SCONFIG

The Server Core installation option of Windows Server 2008 and R2 provides the following benefits:

Reduced maintenance - Because the Server Core installation option installs only what is required to have a manageable server for the AD DS, AD LDS, AD CS, DHCP Server, DNS Server, File Services, Print Services, Web Server and Hyper-V server roles, less maintenance is required than on a full installation of Windows Server 2008.
Reduced attack surface - Because Server Core installations are minimal, there are fewer applications running on the server, which decreases the attack surface.
Reduced management - Because fewer applications and services are installed on a server running the Server Core installation, there is less to manage.
Less disk space required - A Server Core installation requires only about 1.5 gigabyte (GB) of disk space to install and approximately 2 GB for operations after the installation.
Lower risk of bugs - Reducing the amount of code can help reduce the amount of bugs.


To run SCONFIG simply enter sconfig.cmd in the command prompt window, and press Enter.