static bool TryConnectToServer() { SqlConnection connection = new SqlConnection(ServerParameters.GetServerConnectionString()); try { connection.Open(); connection.Close(); } catch { return(false); } finally { connection.Dispose(); } return(true); }
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); }
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); }
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); } }
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); }