Отладка дает результат, но не заполняется - PullRequest
1 голос
/ 01 декабря 2010

У меня есть такая функция в одном классе

public static DataSet GetAllUppercasedTables()
{
  //An instance of the connection string is created to manage the contents of the connection string.
  using(var sConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]))
  {
     //To Open the connection.
     sConnection.Open();

     //Query to select the tables having their names in uppercased format.
     string selectUppercasedTables = @"SELECT  NAME
                                       FROM  sysobjects 
                                       WHERE UPPER(name) COLLATE Latin1_General_BIN = name COLLATE Latin1_General_BIN 
                                       AND OBJECTPROPERTY(ID,N'IsTable')=1
                                       AND OBJECTPROPERTY(ID,N'IsMSShipped')=0 ";
      //Create the command object
      using(var sCommand = new SqlCommand(selectUppercasedTables, sConnection))
      {
         try
         {
           //Create the dataset.
           DataSet dsUppercasedTables = new DataSet("INFORMATION_SCHEMA.TABLE_CONSTRAINTS ");

           //Create the dataadapter object.
           SqlDataAdapter da = new SqlDataAdapter(selectUppercasedTables, sConnection);

           //Provides the master mapping between the sourcr table and system.data.datatable
           da.TableMappings.Add("Table", "INFORMATION_SCHEMA.TABLE_CONSTRAINTS ");

           //Fill the dataadapter.
           da.Fill(dsUppercasedTables);

           //Bind the result combobox with non primary key table names
           DataViewManager dsv = dsUppercasedTables.DefaultViewManager;
           return dsUppercasedTables;
         }
         catch(Exception ex)
         {
           //Handles the exception and log that to the EventLog with the original message.
           EventLog log = new EventLog("Application");
           log.Source = "MFDBAnalyser";
           log.WriteEntry(ex.Message);
           return null;
         }
         finally
         {
           //checks whether the connection is still open.
           if(sConnection.State != ConnectionState.Closed)
           {
             sConnection.Close();
           }
         }
       }
     }
   }

И я вызываю эту функцию в другом классе, как этот

public void GetTablesWithUpperCaseName()
{
  DataSet dsUppercasedTables = default(DataSet);
  try
  {
    dsUppercasedTables = DataAccessMaster.GetAllUppercasedTables();

    **dgResultView.DataSource** = dsUppercasedTables.Tables["INFORMATION_SCHEMA.TABLE_CONSTRAINTS"];
  }
  catch(Exception ex)
  {
    //All the exceptions are handled and written in the EventLog.
    EventLog logException = new EventLog("Application");
    logException.Source = "MFDBAnalyser";
    logException.WriteEntry(ex.Message);
  }
}

Я отлаживал его почти в каждой требуемой точке, он дает хороший результат до

Кто-нибудь может мне помочь!

1 Ответ

2 голосов
/ 01 декабря 2010

В любом случае, оберните ваши SqlConnection, DataSet и SqlDataAdapter в блоке using.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...