AzurePoolCrossDbGenerator/DbAccess.cs
/// <summary>
/// Returns a short form of column definition, all nullable.
/// </summary>
/// <param name="connectionString"></param>
/// <param name="tableName"></param>
/// <returns></returns>
Returns a short form of column definition, all nullable.
Returns a short form of column definition all nullable .
public static string GetTableColumns(string connectionString, string tableName)
        {
            string queryString = @"select COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE 
                from INFORMATION_SCHEMA.COLUMNS
                where table_name = @table_name";
            System.Text.StringBuilder sb = new StringBuilder();
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@table_name", tableName);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        string colName = reader["COLUMN_NAME"].ToString();
                        string colType = reader["DATA_TYPE"].ToString();
                        string colLen = reader["CHARACTER_MAXIMUM_LENGTH"].ToString();
                        string colPrecision = reader["NUMERIC_PRECISION"].ToString();
                        string colScale = reader["NUMERIC_SCALE"].ToString();
                        sb.AppendLine(ItemDefinition(colName, colType, colLen, colPrecision, colScale));
                        if (colType == "text" || colType == "image")
                        {
                            Program.WriteLine($"Incompatible type: {tableName}..{colName} {colType} must be fixed in the DB first.", ConsoleColor.Red);
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return sb.ToString().TrimEnd(trailingChars.ToCharArray());
        }
public static string GetTableColumns ( string connectionString , string tableName ) { string queryString = @"select COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE 
                from INFORMATION_SCHEMA.COLUMNS
                where table_name = @table_name" ; System . Text . StringBuilder sb = new StringBuilder ( ) ; using ( SqlConnection connection = new SqlConnection ( connectionString ) ) { SqlCommand command = new SqlCommand ( queryString , connection ) ; command . Parameters . AddWithValue ( " " , tableName ) ; connection . Open ( ) ; SqlDataReader reader = command . ExecuteReader ( ) ; try { while ( reader . Read ( ) ) { string colName = reader [ " " ] . ToString ( ) ; string colType = reader [ " " ] . ToString ( ) ; string colLen = reader [ " " ] . ToString ( ) ; string colPrecision = reader [ " " ] . ToString ( ) ; string colScale = reader [ " " ] . ToString ( ) ; sb . AppendLine ( ItemDefinition ( colName , colType , colLen , colPrecision , colScale ) ) ; if ( colType == " " || colType == " " ) { Program . WriteLine ( $" Incompatible type:  { tableName } .. { colName } { colType }  must be fixed in the DB first. " , ConsoleColor . Red ) ; } } } finally { reader . Close ( ) ; } } return sb . ToString ( ) . TrimEnd ( trailingChars . ToCharArray ( ) ) ; }
Returns a short form of column definition, all nullable.
Returns a short form of column definition all nullable .
// select column definitions from INFORMATION_SCHEMA.COLUMNS // read the column definition // add to the list // display a warning if incompatible data type was encountered // remove trailing , and new line
None
connectionString
string
None
tableName
string
None