Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
              Van toepassing op:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
SQL-database in Microsoft Fabric Preview
SMO-programma's kunnen de equivalente Transact-SQL instructies vastleggen en vastleggen die door het programma zijn uitgegeven in plaats van, of naast de instructies die door het programma worden uitgevoerd. U schakelt de opnamemodus in met behulp van het ServerConnection object of met behulp van de ConnectionContext eigenschap van het Server object.
Example
Als u een codevoorbeeld wilt gebruiken dat is opgegeven, moet u de programmeeromgeving, de programmeersjabloon en de programmeertaal kiezen waarin u uw toepassing wilt maken. Zie Een Visual C# SMO-project maken in Visual Studio .NETvoor meer informatie.
Opnamemodus inschakelen in Visual Basic
In dit codevoorbeeld wordt de opnamemodus ingeschakeld en worden vervolgens de Transact-SQL opdrachten in de capturebuffer weergegeven.
'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Set the execution mode to CaptureSql for the connection.
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.CaptureSql
'Make a modification to the server that is to be captured.
srv.UserOptions.AnsiNulls = True
srv.Alter()
'Iterate through the strings in the capture buffer and display the captured statements.
Dim s As String
For Each s In srv.ConnectionContext.CapturedSql.Text
    Console.WriteLine(s)
Next
'Execute the captured statements.
srv.ConnectionContext.ExecuteNonQuery(srv.ConnectionContext.CapturedSql.Text)
'Revert to immediate execution mode. 
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql
Opnamemodus inschakelen in Visual C#
In dit codevoorbeeld wordt de opnamemodus ingeschakeld en worden vervolgens de Transact-SQL opdrachten in de capturebuffer weergegeven.
{   
// Connect to the local, default instance of SQL Server.   
Server srv;   
srv = new Server();   
// Set the execution mode to CaptureSql for the connection.   
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.CaptureSql;   
// Make a modification to the server that is to be captured.   
srv.UserOptions.AnsiNulls = true;   
srv.Alter();   
// Iterate through the strings in the capture buffer and display the captured statements.   
string s;   
foreach ( String p_s in srv.ConnectionContext.CapturedSql.Text ) {   
   Console.WriteLine(p_s);   
}   
// Execute the captured statements.   
srv.ConnectionContext.ExecuteNonQuery(srv.ConnectionContext.CapturedSql.Text);   
// Revert to immediate execution mode.   
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql;   
}