Megosztás a következőn keresztül:


Rögzítési mód használata

A következőkre vonatkozik:SQL ServerAzure SQL DatabaseAzure SQL Managed InstanceAzure Synapse AnalyticsSQL-adatbázis a Microsoft Fabricben

Az SMO-programok rögzíthetik és rögzíthetik a program által kiadott egyenértékű Transact-SQL utasításokat a program által végrehajtott utasítások helyett vagy azon felül. A rögzítési módot az ServerConnection objektum használatával vagy az ConnectionContextServer objektum tulajdonságával engedélyezheti.

Example

A megadott kód példájának használatához ki kell választania a programozási környezetet, a programozási sablont és azt a programozási nyelvet, amelyben létre szeretné hozni az alkalmazást. További információ: Visual C# SMO-projekt létrehozása a Visual Studio .NET-.

Rögzítési mód engedélyezése a Visual Basicben

Ez a példakód lehetővé teszi a rögzítési módot, majd megjeleníti a rögzítési pufferben tárolt Transact-SQL parancsokat.

'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

Rögzítési mód engedélyezése a Visual C-ben#

Ez a példakód lehetővé teszi a rögzítési módot, majd megjeleníti a rögzítési pufferben tárolt Transact-SQL parancsokat.

{   
// 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;   
}