AzurePoolCrossDbGenerator/DbAccess.cs
/// <summary>
/// Returns combined text from sys.syscomments for the object, assuming the object names are unique and no object is needed.
/// </summary>
/// <param name="connectionString"></param>
/// <param name="objectName"></param>
/// <returns></returns>
Returns combined text from sys.syscomments for the object, assuming the object names are unique and no object is needed.
Returns combined text from sys . syscomments for the object assuming the object names are unique and no object is needed .
public static string GetObjectText(string connectionString, string objectName)
        {
            string queryString = $"select com.text, com.colid from sys.all_objects obj join sys.syscomments com on obj.object_id = com.id where name = @objectName order by com.colid";
            StringBuilder sb = new StringBuilder(); 
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@objectName", objectName);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    if (!reader.HasRows) return null;
                    while (reader.Read())
                    {
                        string sqlText = reader["text"].ToString();
                        sb.Append(sqlText);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return sb.ToString();
        }
public static string GetObjectText ( string connectionString , string objectName ) { string queryString = $" select com.text, com.colid from sys.all_objects obj join sys.syscomments com on obj.object_id = com.id where name = @objectName order by com.colid " ; StringBuilder sb = new StringBuilder ( ) ; using ( SqlConnection connection = new SqlConnection ( connectionString ) ) { SqlCommand command = new SqlCommand ( queryString , connection ) ; command . Parameters . AddWithValue ( " " , objectName ) ; connection . Open ( ) ; SqlDataReader reader = command . ExecuteReader ( ) ; try { if ( ! reader . HasRows ) return null ; while ( reader . Read ( ) ) { string sqlText = reader [ " " ] . ToString ( ) ; sb . Append ( sqlText ) ; } } finally { reader . Close ( ) ; } } return sb . ToString ( ) ; }
Returns combined text from sys.syscomments for the object, assuming the object names are unique and no object is needed.
Returns combined text from sys . syscomments for the object assuming the object names are unique and no object is needed .
// query sys.syscomments to get the source TSQL code for the DB object // output container for the SQL text // check if there was any data returned at all // read the source SQL from `text` column
None
connectionString
string
None
objectName
string
None