--view linked servers
exec sp_linkedservers
--OR
select * from sys.servers where is_linked = 1
--add a linked server
EXEC sp_addlinkedserver
@server=N'STAGINGCONNECT',
@srvproduct=N'SQL Sever',
@provider=N'SQLNCLI',
@datasrc=N'DB7830F';
--view the linked servers and the logins to the linked server
select s.name, p.principal_id, l.remote_name
from sys.servers s
join sys.linked_logins l
on s.server_id = l.server_id
left join sys.server_principals p
on l.local_principal_id = p.principal_id
where s.is_linked = 1
This blog is created to add all the information and experiences that I have learnt while working on MS sql server as a DBA. The blog is also updated frequently with the real world problem that I encounter hands on at work and the resolutions to resolve them. I hope this blog will be of some use to you and you will revisit. Thank you for stopping by and you are welcome to leave comments.
Thursday, October 29, 2015
Thursday, October 22, 2015
Work Adventure: Fix Orphaned user
When I restored a database to a new server, the users were imported but the login were not. The database users were imported as the orphan users in SQL 2012
Here is how I found the orphaned users in a database
EXEC sp_change_users_login @Action='Report'
--OR we can run the following in the current database context
select * from sysusers where issqluser = 1 and (sid <> 0x0
and sid is not null)
and (LEN(sid) <= 16 ) AND suser_sname(sid) is null
-----------------------------------------
The in order to link the orphan user to the existing login I did the following
sp_change_users_login 'Update_One', 'OrphanUser, 'Logintolinkto'
Here is how I found the orphaned users in a database
EXEC sp_change_users_login @Action='Report'
--OR we can run the following in the current database context
select * from sysusers where issqluser = 1 and (sid <> 0x0
and sid is not null)
and (LEN(sid) <= 16 ) AND suser_sname(sid) is null
-----------------------------------------
The in order to link the orphan user to the existing login I did the following
sp_change_users_login 'Update_One', 'OrphanUser, 'Logintolinkto'
Friday, October 2, 2015
Configuring Dbmail
--check for operators
use msdb
Go
select * from msdb.dbo.sysoperators
--add operators
use msdb
Go
exec dbo.sp_add_operator @name= User1, @enabled = 1, @email_address = 'user1e@abc.com'
exec dbo.sp_add_operator @name= 'User2, @enabled = 1, @email_address = 'user2@abc.com'
--enable the database mail
USE master
GO
sp_configure 'show advanced options',1
GO
RECONFIGURE WITH OVERRIDE
GO
sp_configure 'Database Mail XPs',1
GO
RECONFIGURE
GO
--Set up account and profile.
--One last thing but most important thing left is Letting the SQL Server Agent Talk to Database Mail. If we do not perform this step we get the following error
Avoiding 'Failed to notify <operator> via email' errors
use msdb
Go
select * from msdb.dbo.sysoperators
--add operators
use msdb
Go
exec dbo.sp_add_operator @name= User1, @enabled = 1, @email_address = 'user1e@abc.com'
exec dbo.sp_add_operator @name= 'User2, @enabled = 1, @email_address = 'user2@abc.com'
--enable the database mail
USE master
GO
sp_configure 'show advanced options',1
GO
RECONFIGURE WITH OVERRIDE
GO
sp_configure 'Database Mail XPs',1
GO
RECONFIGURE
GO
--Set up account and profile.
--One last thing but most important thing left is Letting the SQL Server Agent Talk to Database Mail. If we do not perform this step we get the following error
Avoiding 'Failed to notify <operator> via email' errors
- -Highlight the "SQL Server Agent" in the object Explorer
- -Go to Properties
- -Go to Alert system options
- - Check the enable profile on and select the profile
Error: Failed to notify via email
The above error occurs when we forget to perform the step to let the SQL Server Agent Talk to Database Mail
To perform that , follow the following steps -
-Highlight the "SQL Server Agent" in the object Explorer
-Go to Properties
-Go to Alert System options
- Check the enable profile on and select the profile in the mail Session section.
To perform that , follow the following steps -
-Highlight the "SQL Server Agent" in the object Explorer
-Go to Properties
-Go to Alert System options
- Check the enable profile on and select the profile in the mail Session section.
Subscribe to:
Posts (Atom)