sql-server-2008 – 数据库邮件的脚本设置

前端之家收集整理的这篇文章主要介绍了sql-server-2008 – 数据库邮件的脚本设置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用sql Server 2008 GUI设置数据库邮件配置文件帐户在我的测试服务器上,我现在想要复制到我们的生产数据库.

有没有办法生成一个脚本来做到这一点?

解决方法

AFAIK,没有办法从SSMS中脚本化,但您可以在Tsql中创建一个可传输脚本,并将其重用于所有服务器.这是一个很好的例子,让你开始这样做:
USE [master]
GO
sp_configure 'show advanced options',1
GO
RECONFIGURE WITH OVERRIDE
GO
sp_configure 'Database Mail XPs',1
GO
RECONFIGURE 
GO
-- Create a New Mail Profile for Notifications
EXECUTE msdb.dbo.sysmail_add_profile_sp
       @profile_name = 'DBA_Notifications',@description = 'Profile for sending Automated DBA Notifications'
GO
-- Set the New Profile as the Default
EXECUTE msdb.dbo.sysmail_add_principalprofile_sp
    @profile_name = 'DBA_Notifications',@principal_name = 'public',@is_default = 1 ;
GO
-- Create an Account for the Notifications
EXECUTE msdb.dbo.sysmail_add_account_sp
    @account_name = 'sqlMonitor',@description = 'Account for Automated DBA Notifications',@email_address = 'email@domain.com',-- Change This
    @display_name = 'sql Monitor',@mailserver_name = 'smtp.domain.com'  -- Change This
GO
-- Add the Account to the Profile
EXECUTE msdb.dbo.sysmail_add_profileaccount_sp
    @profile_name = 'DBA_Notifications',@account_name = 'sqlMonitor',@sequence_number = 1
GO

另一个选择是利用SMO,通过.NET或者PowerShell来生成脚本. SMO的参考文献是:

SqlMail Class

更新:

以下是Powershell和SMO的简单说明:

[void][reflection.assembly]::LoadWithPartialName("Microsoft.sqlServer.Smo");

#Set the server to script from
$ServerName = "ServerName";

#Get a server object which corresponds to the default instance
$srv = New-Object -TypeName Microsoft.sqlServer.Management.SMO.Server $ServerName

#Script Database Mail configuration from the server
$srv.Mail.Script();
原文链接:https://www.f2er.com/mssql/75251.html

猜你在找的MsSQL相关文章