Posts

Showing posts from October, 2017

Folder creation in Windows by using Windows powershell

Image
To day i have done one more task with power shell command which creates a folder in D drive. I have written the script like below. Though you can find the error in the script, however it create a folder in the respective drive.

Connecting SQL Server from Windows Powershell

Image
This is my first effort connecting sql server through windows power shell command. I am able to access the SQL Server default instance with the below command and able to export or get those results to notepad.

Databases status showing as Not Synchronizing/Recovery Pending in SQL Server Always On Secondary replica.

Image
Recently i have come across one issue in my environment where i found databases have gone into Not Synchronizing/Recovery pending state in one of the secondary replicas as shown given below. In though above image there are 4 databases have gone into NotSynchronizing/ Recovery Pending state. However i am going explain here about one database. Check the same database status Under Availability Groups-->Under Avaiability Databases. If you see the status of the database has shown like this If you see the database status shown as in Red. Now runt the below command in Secondary replica. ALTER DATABSE  DatabaseName SET HADR OFF Once you run this command you can see the database status will change to Warning mode from error mode as shown below. At the same time you observer same database status in under databases it will change to restoring mode from Not Synchronizing /Recovery pending state to Restoring mode as shown below. Now you right click on the status o

DATABASE LEVEL PERMISSIONS ON SQL SERVER

Image
The below image will explain you about Database level permissions at database level. Extracted from BOL.

Getting logins account information from the server who are having sysadmin Privilege

/****** Getting logins account information  from the server who are having sysadmin Privilege. But we can use this for other servers also if need. Script Date: 10/4/2017 Author: Ramesh. M ******/ SET NOCOUNT ON USE master go DECLARE @Table TABLE (ServerRole VARCHAR(50),[Member] VARCHAR(100),MemberSID VARCHAR(1000)) DECLARE @Table1 TABLE (Sno INT IDENTITY(1,1),Name VARCHAR(2000)) DECLARE @CaptureLoop TABLE (accountname varchar(200),types varchar(200),privelege varchar(100), MappedLogin varchar(100),PermissionPath VARCHAR(100)) INSERT INTO @Table1 (Name) SELECT NAME FROM sys.server_principals WHERE type IN('g'); DECLARE @i int declare @Count INT declare @Catchvalue VARCHAR(50) SET @i=0 SELECT @Count=COUNT(*) FROM sys.server_principals WHERE type IN('g') --PRINT @Count INSERT INTO @Table (ServerRole,[Member],MemberSID) exec sp_helpsrvrolemember 'sysadmin' WHILE @I<@Count BEGIN   set @i=@i+1   SELECT @Catchvalue=Name   FROM @