我需要提取在我的实例中可用的存储过程列表。我使用以下 T-SQL 语句来获取给定数据库中的存储过程。
select *
from MyDatabase.information_schema.routines
where routine_type = 'Procedure'
Run Code Online (Sandbox Code Playgroud)
有没有脚本可以获取所有的存储过程或者通过存储过程名称来检查存储过程的数据库名称?
我已经在 INSTANCE1 和 INSTANCE2 中配置了数据库邮件。每当我尝试使用以下代码发送邮件时,我都会在 INSTANCE1 中得到“邮件排队”的输出。
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Vinesh',
@recipients = 'VineshSenthilvel@gmail.com',
@body = 'The stored procedure finished successfully.',
@subject = 'Automated Success Message - Default' ;
Run Code Online (Sandbox Code Playgroud)
但是邮件没有发送到我的邮箱。我尝试在 INSTANCE2 中执行上述查询,邮件已送达。我已经验证数据库邮件配置在这两个实例中似乎都是完美的。
我可以在数据库邮件日志中找到数据库邮件进程正在关闭。还发现了下面提到的错误。
1) Exception Information
===================
Exception Type: Microsoft.SqlServer.Management.SqlIMail.Server.Common.BaseException
Message: The Transaction not longer valid.
Data: System.Collections.ListDictionaryInternal
TargetSite: Void ValidateConnectionAndTransaction()
HelpLink: NULL
Source: DatabaseMailEngine
StackTrace Information
===================
at Microsoft.SqlServer.Management.SqlIMail.Server.DataAccess.ConnectionManager.ValidateConnectionAndTransaction()
at Microsoft.SqlServer.Management.SqlIMail.Server.DataAccess.ConnectionManager.RollbackTransaction()
at Microsoft.SqlServer.Management.SqlIMail.IMailProcess.QueueItemProcesser.GetDataFromQueue(DataAccessAdapter da, Int32 lifetimeMinimumSec)
at Microsoft.SqlServer.Management.SqlIMail.IMailProcess.QueueItemProcesser.ProcessQueueItems(String dbName, String dbServerName, Int32 lifetimeMinimumSec, LogLevel loggingLevel, Byte[] encryptionKey, Int32 …
Run Code Online (Sandbox Code Playgroud) 我的本地机器中有一个脚本文件。我必须打开 SSMS 并在 SSMS 中打开查询并执行查询。
为了打开 SSMS 和查询,我使用了以下 PowerShell 脚本来完成它。
ssms.exe 'E:\PowerShell_PROD\Screenshot\ServerDetails.sql' -E -S localhost
Run Code Online (Sandbox Code Playgroud)
如何使用 PowerShell 运行此查询以及如何关闭此查询窗口?
我这样做的原因是我必须获取 SQL Server 属性和其他信息的证据。为此,我有一个 PowerShell 脚本来捕获屏幕截图。
我正在准备 PowerShell 脚本,该脚本在 SSMS 中运行每个查询并捕获结果并保存到指定路径。现在可以在 SSMS 中打开查询并捕获屏幕截图,但我无法运行查询。