示例#1
0
        static bool TryConnectToServer()
        {
            SqlConnection connection = new SqlConnection(ServerParameters.GetServerConnectionString());

            try {
                connection.Open();
                connection.Close();
            }
            catch {
                return(false);
            }
            finally {
                connection.Dispose();
            }
            return(true);
        }
示例#2
0
        public static bool CreateDataLayer()
        {
            if (!TryConnectToServer())
            {
                return(false);
            }
            IDataStore store;

            try {
                store = XpoDefault.GetConnectionProvider(ServerParameters.GetDBConnectionString(), AutoCreateOption.DatabaseAndSchema);
            }
            catch {
                return(false);
            }
            XpoDefault.DataLayer = new SimpleDataLayer(store);
            return(true);
        }
示例#3
0
        public static PivotGridDemoDBDataContext GetContext()
        {
            PivotGridDemoDBDataContext context = new PivotGridDemoDBDataContext(ServerParameters.GetDBConnectionString());
            bool databaseOK = false;

            try {
                databaseOK = context.DatabaseExists();
            }
            finally {
                if (!databaseOK)
                {
                    context.Dispose();
                    context = null;
                }
            }
            return(context);
        }
示例#4
0
 public static int CalculateRecordCount()
 {
     try {
         using (SqlConnection connection = new SqlConnection(ServerParameters.GetDBConnectionString())) {
             connection.Open();
             using (SqlCommand command = new SqlCommand("select count(OID) as count from [dbo].[Sales]", connection)) {
                 return((int)command.ExecuteScalar());
             }
         }
     } catch {
         try {
             new SqlConnection(ServerParameters.GetServerConnectionString()).Open();
         } catch {
             return(-1);
         }
         return(0);
     }
 }
示例#5
0
        public static DataSet GetDataSet(string sql)
        {
            string         connectionString = ServerParameters.GetDBConnectionString();
            SqlConnection  connection       = new SqlConnection(connectionString);
            SqlDataAdapter adapter          = new SqlDataAdapter(sql, connection);
            DataSet        dataSet;

            try {
                dataSet = new DataSet();
                adapter.Fill(dataSet, "sales");
            }
            catch {
                dataSet = null;
            }
            finally {
                connection.Dispose();
            }
            return(dataSet);
        }