SQL Server Error Logs
SQL Server Error Logs
SQL Server Error Logs
* Error Logs maintains events raised by SQL Server database engine or Agent.
* Error Logs are main source for troubleshooting SQL Server problems.
* SQL Server supports 2 types of error logs
* SQL Server Logs
* SQL Agent Logs
FAQ : - What is recorded in error logs?
1.
2.
3.
4.
5.
6.
7.
8.
Scripts
WMI Error Solution
Copy the following script in notepad and save with "wmi.bat"
Double click on the file, WMI service is installed then continue setup.
@echo on
cd /d c:\temp
if not exist %windir%\system32\wbem goto TryInstall
cd /d %windir%\system32\wbem
net stop winmgmt
winmgmt /kill
if exist Rep_bak rd Rep_bak /s /q
rename Repository Rep_bak
for %%i in (*.dll) do RegSvr32 -s %%i
for %%i in (*.exe) do call :FixSrv %%i
for %%i in (*.mof,*.mfl) do Mofcomp %%i
net start winmgmt
goto End
:FixSrv
if /I (%1) == (wbemcntl.exe) goto SkipSrv
if /I (%1) == (wbemtest.exe) goto SkipSrv
if /I (%1) == (mofcomp.exe) goto SkipSrv
%1 /RegServer
:SkipSrv
goto End
:TryInstall
if not exist wmicore.exe goto End
wmicore /s
net start winmgmt
:End
Installing and Configuring SQL Server 2008
System Requirements
* O/S
* Memory
* CPU
* HDD
* Next
* Select "I Accept........"
* Next
* Under Feature Selection
select
Database Engine Services
SQL Server Replication
Full Text Search....
* Next
Note:
1. First time, select shared features also
2. Install SQL Server always in NTFS not in FAT32. NTFS provides high security and high
performance.
* Select "Named Instance and enter: TEST
Instance Root Directory: d:\SQLSERVER
Next
* Next
* Under "Server Configuration" Click on button
Use Same account..........
Enter
Account Name: SQLDBEngine_user
password
hyd@123
OK
* Next
FAQ:- Once I install SQL Server what are the logins created automatically?
Ans:
SS 2005
* sa
* BUILTIN\Administrators
SS 2008
* sa
* Login for service account
* Logins for added users in wizard
FAQ: - What are the differences in the installation of SS 2005 and SS 2008?
Ans
* In SQL Server 2005 there is no
* Installation Center
* Upgrading, edition change, rebuilding system databases etc we have to perform
by running setup from command prompt.
* There is no "ConfigurationFile.ini"
* Next
* Close
Post Installation Steps
1. Verifying installation
* We can verify installation process using Summary.txt file, present in
C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log
2. Verifying instance folders
* For every instance the following folders are created in installation directory.
MSSQL10.<instanceName>
MSSQL
* BACKUP
* Binn - Consists of .exe and .dlls
* DATA - data and T.log files
* FTData
* Install - consists of .sql files
* Jobs - jobs and maintenance plans
* Log
- Error logs
* repldata- Replication snapshot folder
* Upgrade (2008)
3. Configuring Error logs
* Error logs maintains events raised by SQL Server.
* Consists of both errors and information.
* Error logs are present in LOG folder of respective instance.
* SS supports
1 Current Log
6 Archieve logs by default.
* Current Log has all the events from server restart.
* Once the server is restarted all the events are flushed from current log into Archieve1 and from
Archieve1 to Archieve2 etc. This process is called recycling error logs.
* We can recycle error logs explicitly without server restart using
sp_cycle_errorlog
* We can read error logs using sp_readerrorlog
* SS supports min 6 and max 99 error logs
* How to configure?
* Go to SSMS --> Object Explorer --> Management
* R.C on SQL Server Logs --> Configure
select checkbox "Limit no of ............"
Maximum logs..........: 20
* OK
FAQ: - When I am starting SQL Server it was not started successfully. What are the possible
scenarios? and how to troubleshoot it?
Possible Scenarios
1. Logon Failure
* Problem with service account.
2. 17113
* Master files are moved or corrupted
3. 3417
* After moving master files we have not granted read/write permissions on new folder
* Or any one startup parameter is missing.
How to troubleshoot?
* Check windows event log
* start --> run --> eventvwr
* System
* In the right pane double click on Error
* Using SQL Server error log
* Go to LOG folder of respective instance
* Open ERRORLOG in notepad and check for errors
Dead Locks in SQL Server
One thing that will you most certainly face at some time as a DBA is dealing with
deadlocks. A deadlock occurs when two processes are trying to update the same record or
set of records, but the processing is done in a different order and therefore SQL Server
selects one of the processes as a deadlock victim and rolls back the statements.
You have two sessions that are updating the same data, session 1 starts a transaction
updates table A and then session 2 starts a transaction and updates table B and then
updates the same records in table A.
Session 1 then tries to update the same records in table B. At this point it is impossible for
the transactions to be committed, because the data was updated in a different order and
SQL Server selects one of the processes as a deadlock victim.
To further illustrate how deadlocks work you can run the following code in the Northwind
database.
To create a deadlock you can issue commands similar to the commands below.
Step Commands
1
--issue this command in query window (1) to undo all of the changes
Rollback
--go back to query window (2) and run these commands to undo changes
Rollback
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.
k.
l.
m.
n.
Each user session might have one or more tasks running on its behalf where each task might acquire or wait to
acquire a variety of resources. The following types of resources can cause blocking that could result in a deadlock.
Locks. Waiting to acquire locks on resources, such as objects, pages, rows, metadata, and
applications can cause deadlock. For example, transaction T1 has a shared (S) lock on row r1 and is waiting to get
an exclusive (X) lock on r2. Transaction T2 has a shared (S) lock on r2 and is waiting to get an exclusive (X) lock on
row r1. This results in a lock cycle in which T1 and T2 wait for each other to release the locked resources.
Worker threads. A queued task waiting for an available worker thread can cause deadlock. If the
queued task owns resources that are blocking all worker threads, a deadlock will result. For example, session S1
starts a transaction and acquires a shared (S) lock on row r1 and then goes to sleep. Active sessions running on all
available worker threads are trying to acquire exclusive (X) locks on row r1. Because session S1 cannot acquire a
worker thread, it cannot commit the transaction and release the lock on row r1. This results in a deadlock.
Memory. When concurrent requests are waiting for memory grants that cannot be satisfied with
the available memory, a deadlock can occur. For example, two concurrent queries, Q1 and Q2, execute as userdefined functions that acquire 10MB and 20MB of memory respectively. If each query needs 30MB and the total
available memory is 20MB, then Q1 and Q2 must wait for each other to release memory, and this results in a
deadlock.
Parallel query execution-related resources Coordinator, producer, or consumer threads
associated with an exchange port may block each other causing a deadlock usually when including at least one other
process that is not a part of the parallel query. Also, when a parallel query starts execution, SQL Server determines
the degree of parallelism, or the number of worker threads, based upon the current workload. If the system workload
unexpectedly changes, for example, where new queries start running on the server or the system runs out of worker
threads, then a deadlock could occur.
Multiple Active Result Sets (MARS) resources. These resources are used to control interleaving
of multiple active requests under MARS
User resource. When a thread is waiting for a resource that is potentially controlled by a
user application, the resource is considered to be an external or user resource and is treated like a lock.
Session mutex. The tasks running in one session are interleaved, meaning that only one
task can run under the session at a given time. Before the task can run, it must have exclusive access to the session
mutex.
Transaction mutex. All tasks running in one transaction are interleaved, meaning that
only one task can run under the transaction at a given time. Before the task can run, it must have exclusive access to
the transaction mutex.
Deadlock Detection
All of the resources listed in the section above participate in the Database Engine deadlock detection scheme.
Deadlock detection is performed by a lock monitor thread that periodically initiates a search through all of the tasks
in an instance of the Database Engine. The following points describe the search process:
The default interval is 5 seconds.
If the lock monitor thread finds deadlocks, the deadlock detection interval will drop from 5
seconds to as low as 100 milliseconds depending on the frequency of deadlocks.
If the lock monitor thread stops finding deadlocks, the Database Engine increases the intervals
between searches to 5 seconds.
If a deadlock has just been detected, it is assumed that the next threads that must wait for a lock
are entering the deadlock cycle. The first couple of lock waits after a deadlock has been detected will immediately
trigger a deadlock search rather than wait for the next deadlock detection interval. For example, if the current
interval is 5 seconds, and a deadlock was just detected, the next lock wait will kick off the deadlock detector
immediately. If this lock wait is part of a deadlock, it will be detected right away rather than during next deadlock
search.
To help minimize deadlocks:
Access objects in the same order.
Avoid user interaction in transactions.
Keep transactions short and in one batch.
Use a lower isolation level.
Use a row versioning-based isolation level.
Set READ_COMMITTED_SNAPSHOT database option ON to enable read-committed
transactions to use row versioning.
Use snapshot isolation.
Use bound connections.
Query Architecture
Performance Tuning, Monitoring and Troubleshooting
* As part of performance tuning we have to analyze and work with
* Physical I/O and Logical I/O
* CPU usage
* Memory usage
* Database Design
* Application's db programming methods
Query Architecture
* Once the query is submitted to Database Engine for first time it performs the following
* Parsing
(Compiling)
* Resolving (Verifying syntax, table, col names etc)
* Optimizing (Generating execution plan)
* Executing (Executing query)
* For next time if the query was executed with same case and same no of characters i.e
extra spaces then the query is executed by taking existing plan.
* To display cached plans
SELECT cp.objtype AS PlanType,
OBJECT_NAME(st.objectid,st.dbid) AS ObjectName,
cp.refcounts AS ReferenceCounts,cp.usecounts AS UseCounts,
tasks.
with no
clustered index
select * from prods where pid=2 -- press ctrl+L to check execution plan
insert prods values(3,'Pencils',500) -- Check this row is inserted as second record.
Note: A table without clustered index is called HEAP where the rows and pages of the
not present in any order.
table are
FillFactor.
Page Split-----------* Due to regular changes in the table if the index pages are full to allocate memory for
the index
key columns SS takes remaining rows into new page. This process is called
Page split.
* Page split increases size of index and the index pages order changes.
* This situation where unused free space is available and the index pages are not in the
order of key
column values is called fragmentation.
* To find fragmentation level we can use
dbcc showcontig
or
We can use sys.dm_db_index_physical_stats DMF as follows
SELECT a.index_id, name, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats
(DB_ID('AdventureWorks'),
OBJECT_ID('Production.Product'), NULL, NULL, NULL)
AS a JOIN sys.indexes AS b
ON a.object_id = b.object_id
AND a.index_id =b.index_id;
* To control fragmentation we can either reorganize the index or rebuild the index.
1. Reorganizing Index * It is the process of arranging the index pages according to the order of index
key column values.
* If the fragmentation level is more than 5 to 8% and less than 28to 30% then we can reorganize the
indexes.
* It cannot reduce the index size as well as statistics are not updated.
syn:
ALTER INDEX <indexName>/<All> on <tname> REORGANIZE
2. Index Rebuilding * It is the process of deleting and creating fresh index.
* It reduces the size of index and updates statistics
* If the fragmentation level is more than 30% then we can rebuild indexes.
syn:
ALTER INDEX <indexName>/<ALL> on <tname> REBUILD
Note:
If we have mentioned ONLINE INDEX PROCESSING option then rebuilding takes space in TEMPDB.
To check consistancy of a database we can use DBCC CHECKDB('dbName') it disp if any corrupted
pages are present, use space in tempdb.
Transactions and Locks
---------------------------* A transaction is single unit of work which may consists of one or more commands.
* Transactions works with ACID properties
* Automicity
* Consistancy
* Isolation
* Durability
* SQL Server supports 2 types of transactions
* Implicit
* Explicit
* By default SS supports implicit transaction where for every insert, update and delete 3
are stored in T.Log file
Begin tran
insert/update/delete
commit tran
* To implement business logic i.e. according to the required if we want to commit or
changes we can use explicit transactions.
Begin Tran
---commit/rollback tran
* Any transaction which consists of manipulations places locks on the tables.
* By default when we make a db as current db automatically Shared Lock is placed.
* While working with insert,update,delete by default SS places Exclusive lock.
* Type of locks placed on objects depends on isolation levels.
Isolation Levels
------------------* It is a transaction property.
* Types of locks placed by SS on the resource depends on isolation levels.
* SS supports 5 isolation levels
* Read Committed (Default)
* Read Uncommitted
* Repeatable Reads
* Snapshot
* Serializable
* To check the isolation level
records
rollback the
dbcc useroptions
* To set the isolation level
SET TRANSACTION ISOLATION LEVEL <requiredisolationlevel>
* To handle the concurrency related problems SS places locks
* SS supports 2 types of concurrencies
* Optimistic Concurrency
* Uses Shared Locks
* More concurrency
* Pessimistic Concurrency
* Uses Exclusive Locks
* Low concurrency
Ex: Open new query window
--user1
use Test
go
begin tran
update emp set sal=5000
Take new query -->
--user2
use Test
go
select * from emp (--query runs continuesly till user1 session releases lock)
Take new query
--user3
set transaction isolation level read uncommitted
select * from emp
--Take new query
sp_lock
-- To view locks information
or
select * from sys.dm_tran_locks
--check blocking using
sp_who/sp_who2
-- To check locks placed by a particular session
sp_lock <spid>
sp_lock 56
Database Mirroring
Introduction
It is another high availability feature available from SQL Server 2005. Previous versions support
the simple high availability feature called Transaction Log Shipping. Log shipping has its own limitation as
it doesnt support automatic failover as well as there might be data loss. All these limitation we can
overcome with database mirroring.
Database mirroring supports automatic failover and the transactions are applied to standby (Mirror) server
immediately once they are committed at principle server. Like Log shipping no need of backup, copy and
restore operations and jobs.
Points to remember
In Principal server database is in ONLINE state.
In mirror server database is in a restoring state, which means it is not available for incoming requests.
However, we can create a database snapshot of the mirror database, which provides a point-in-time
read-only view of the database.
Advantages and benefits:
minimize
* No automatic failover
* Asynchronous
* High performance
* Principal, Mirror
* No automatic failover
FAQ: - How to enable mirroring feature in SS 2005 RTM?
1.
2.
3.
4.
5.
6.
1.
a.
b.
c.
2.
a.
3.
1.
2.
3.
a.
b.
c.
4.
5.
6.
7.
Requirements
SQL Server 2005 with SP1 or SQL Server 2008
Database should be in FULL recovery model.
Service Broker should be enabled on the database.
Both the servers should have either Enterprise or standard editions.
Both the servers should have same edition.
Witness server can have any edition.
Configuring Mirroring Steps
Configuring security and communication between instances
Configuring endpoint
Creating logins for other servers service accounts
Grant connect permission to this logins on endpoints
Create mirror database
Take full and T.Log backup from principle server and restore it in mirror server with NORECOVERY.
Establish mirroring session using ALTER DATABASE command
Steps
Go to SSMS
Connect 2 or 3 instances
For example
CLASS2\sql2K8
Principal
CLASS2\FIRST
Mirror
CLASS2\THIRD
Witness
Note down the above instances service accounts
CLASS2\SQL2K8
(CLASS2\KAREEM)
CLASS2\FIRST
(CLASS2\KAREEM)
CLASS2\THIRD
(CLASS2\SQLUSER)
Verify both Principal and Mirror has same editions or not i.e. Enterprise or Standard.
By running the following command in both the servers
Select serverproperty('edition')
Go to Principal server and create a sample database (In real time environment we have to use existing
database) with the name OptimizeSQL
Create one sample table in the database with some rows.
Take FULL and Transaction Log Backup of OptimizeSQL database in principal server.
Use master
go
backup database OptimizeSQL to disk='\\Class2\backups\OptimizeSQL.bak'
8.
9.
10.
11.
go
backup log OptimizeSQL to disk='\\Class2\backups\OptimizeSQL.bak'
go
Go to Mirror Server and create a folder with the name d:\OptimizeSQL_Files and grant read write
permissions to service account. Restore database by using the Recovery State WITH NORECOVERY
RESTOREDATABASE OptimizeSQL
FROM DISK='\\Class2\backups\OptimizeSQL.bak'
WITH FILE= 1,
MOVE 'OptimizeSQL' TO 'd:\OptimizeSQL_Files\OptimizeSQL.mdf',
MOVE 'OptimizeSQL_log' TO '
d:\OptimizeSQL_Files\OptimizeSQL_1.ldf' ,NORECOVERY
GO
RESTORE LOG OptimizeSQL
FROM DISK='\\Class2\backups\OptimizeSQL.bak'
WITH FILE= 2,NORECOVERY
GO
Configuring Mirroring
Go to Principal Server Right Click on database OptimizeSQL Tasks Mirror
Click on Configure Security Click Next
Next
12. Select Yes if you have witness instance otherwise select No.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
Next Next
Select principal instance Next
Click on Connect select Mirror Server instance name (e.g class2\First)
Select Connect Next
Once again click on Connect button select Witness Server instance name (CLASS2\THIRD) Next
Enter service accounts
Click Next Finish
Close.
Select Do Not Start Mirroring.
Select Start Mirroring
Check the status OK
1.
2.
3.
a.
b.
Points to Remember
One job is created on both the servers
Database Mirroring Monitor Job
Default Partner Timeout is 10Sec.
How can you say that both the dbs are 100% sync?
We can view unsent log and un restored log values. If both are 0 then 100% sync. (In Mirroring Monitor)
We can view Mirroring Failover LSN and Replication LSN with sys.database_mirroring. Both should
be same.
1.
2.
3.
4.
5.
o
o
o
o
1.
o
o
o
2.
o
3.
a.
4. Mirroring States
Synchronizing
Synchronized
Disconnected (If mirror or principal failed)
Suspended (If the principal is un available or unable to send transactions to mirror)
Pending Failover If the unsent log is >0.
5. To change mirroring timeout (Run in principal server)
Alter database OptimizeSQL SET PARTNER TIMEOUT 30
Monitoring Mirroring
We can monitor mirroring using the following options
Using MSDB tables and Views
Using Database Mirroring Monitor
Using Performance Monitor
Using Profiler
Using MSDB tables and Views
To view complete details of mirroring (In Principal Server)
Select * from sys.database_mirroring
To view mirroring endpoint details (In Principal Server)
Select * from sys.database_mirroring_endpoints
To view about Principal, mirror server details and mirroring state run the following query in witness server
Select * from sys.database_mirroring_witnesses
Using Database Mirroring Monitor
We can monitor the following features
* Unsent Log (at principal)
* Un restored Log (at mirror)
* Transaction Rate
* Commit Overhead (Transactions applied rate at mirror)
Ex: Go to principal server and run the following query
use OptimizeSQL
go
declare @n int=100
while @n<=1000000
begin
insert emp values(@n,'Rajesh',60)
set @n+=1
end
b. Right click on OptimizeSQL db --> Tasks -->Launch Database Mirroring Monitor
c. Select "Database Mirroring Monitor"
d. Click on Register Mirror databases
e. Click on Connect and select Mirror Server
f. Select the database OptimizeSQL --> OK
g. Observe the parameters by refreshing (F5) the monitor.
Configuring Thresholds
Go to Mirroring Monitor Select Warnings tab Set Thresholds
Using Performance Monitor
We can monitor the following counters for Mirrored databases
* We can use the performance object called
"<instanceName>:Database Mirroring"
* Counters which we have to observe regularly
* Bytes sends/sec
* Log Harden time (Commit overhead)
* Total sends/sec
* Transaction delay (Principal)
* Pages Sends/sec
1.
2.
3.
4.
5.
1.
2.
3.
1.
2.
3.
1.
2.
Steps
Start run perfmon
Add counter (Ctrl + I) or Click on +symbol, present on toolbar.
Add required counters by selectingMSSQL$SQL2K8:DatabaseMirroringperformance object
To view the changes run the previous script.
Configuring Alerts
Performing Fail Over
Fail over process depends on Operating Modes.
If the operating mode is "High safety with automatic failover" then witness server makes mirror db online
automatically within the configured timeout.
In case of other operating modes we have to perform fail over manually.
In High Performance
Run the following command in mirror server
ALTER DATABASE <dbname> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS
Transfer the logins.
Make the database available to the users and applications.
In High Protection
Run the following commands in Mirror server
ALTER DATABASE <dbname> SET PARTNER OFF; (To break mirroring)
Database comes into restoring state run the following command to take it online
RESTORE DATABASE <dbname> WITH RECOVERY
Quorum
Quorum is a relationship that exists when two or more server instances in a database mirroring session
are connected to each other. Typically, quorum involves three interconnected server instances. When a
witness is set, quorum is required to make the database available. Designed for high-safety mode with
automatic failover, quorum makes sure that a database is owned by only one partner at a time.
Three types of quorum are possible:
Hard Errors
Errors identified by windows and notified to sqlservr.exe file are called hard errors.
A broken connection or wire
A bad network card
A router change
Changes in the firewall
Endpoint reconfiguration
Loss of the drive where the transaction log resides
Operating system or process failure
@binvalue varbinary(256),
@hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint int
DECLARE @secondint int
SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
SELECT @firstint = FLOOR(@tempint/16)
SELECT @secondint = @tempint - (@firstint*16)
SELECT @charvalue = @charvalue +
SUBSTRING(@hexstring, @firstint+1, 1) +
SUBSTRING(@hexstring, @secondint+1, 1)
SELECT @i = @i + 1
END
SELECT @hexvalue = @charvalue
GO
IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
DROP PROCEDURE sp_help_revlogin
GO
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @type varchar (1)
DECLARE @hasaccess int
DECLARE @denylogin int
DECLARE @is_disabled int
DECLARE @PWD_varbinary varbinary (256)
DECLARE @PWD_string varchar (514)
DECLARE @SID_varbinary varbinary (85)
DECLARE @SID_string varchar (514)
DECLARE @tmpstr varchar (1024)
DECLARE @is_policy_checked varchar (3)
DECLARE @is_expiration_checked varchar (3)
END
ELSE BEGIN -- SQL Server authentication
-- obtain password and sid
SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary
(256) )
EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
-- obtain password policy state
SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN
'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0
THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' +
@PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'
IF ( @is_policy_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
END
IF ( @is_expiration_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
END
END
IF (@denylogin = 1)
BEGIN -- login is denied access
SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
END
ELSE IF (@hasaccess = 0)
BEGIN -- login exists but does not have access
SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
END
IF (@is_disabled = 1)
BEGIN -- login is disabled
SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
END
PRINT @tmpstr
END
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb,
@hasaccess, @denylogin
END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO
--step2
EXEC sp_help_revlogin
--step3:
The above s.p generates some output as follows
/* sp_help_revlogin script
** Generated May 25 2009 9:11PM on ONLINE */
-- Login: BUILTIN\Administrators
CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE = [master]
-- Login: NT AUTHORITY\SYSTEM
CREATE LOGIN [NT AUTHORITY\SYSTEM] FROM WINDOWS WITH DEFAULT_DATABASE = [master]
Copy, paste above output in Stand by server instance and run for required logins.
Alternatively you can download the script from
http://support.microsoft.com/kb/918992/
Steps to configure replication
Configuring distributor
Configuring publisher
Creating publication of required type
Creating subscription(s)
Step1: Configuring distributor and publisher
a.
Take three instances
1.
2.
3.
4.
b.
c.
d.
e.
Next
f.
g.
h.
Next
Next
Uncheck the check box present at Server2 Add
i.
Select instance Server1
Next
Enter strong password. (Automatically one login is created in distributor with the name
Distributor_Admin)
m. Next
n.
Next
o.
Finish
j.
k.
l.
1.
2.
3.
4.
Observations
Go to distributor Databases Find the new database Distribution
Go to Security Logins Find a new login Distributor_admin
Go to Server Objects Linked servers Find new linked server repl_distributor
Right Click on Replication Select distributor Properties..
Transactions stored in distribution database are removed after 72 hrs and agents history is removed
after 48 hrs.
To view snapshot folder path Click on publishers click on browse button () present to right side
of publisher name.
Go to SQL Server Agent Jobs Find 6 new jobs are created automatically.
8.
1.
2.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
(
FILE = 'D:\EncryptPrivateKey.key',
ENCRYPTION BY PASSWORD = 'TryToUseOnlyStrongPassword'
)
GO
--step7: Go to second server where need to attach db
USE [master]
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'p@ssw0rd';
GO
CREATE CERTIFICATE MyTDECert
FROM FILE = 'D:\MyTDECert.cert'
WITH PRIVATE KEY (
FILE = 'D:\EncryptPrivateKey.key'
, DECRYPTION BY PASSWORD = 'TryToUseOnlyStrongPassword'
)
--step8: Run step5 in second server. Now db is attached successfully