public void CloseConnection(SqlProxyConnection connection) { if (connection.State == ConnectionState.Open) { connection.Close(); } }
public bool CreateTable(SqlProxyConnection Connection, UserType user) { SqlProxyConnection = Connection; CreateDBTables(); dbVersion = ReadDBVersion; if (dbVersion == -1) { InsertDBVersion(Module(), CurrentVersion()); dbVersion = CurrentVersion(); } if (dbVersion > CurrentVersion()) { var message = string.Format("Wrong version.\nThe Current Database version form module {0} is {1}, while the program version is {2}", Module(), dbVersion, CurrentVersion()); MessageBox.Show(message, "Attention", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } if (dbVersion < CurrentVersion()) { if ((user != UserType.Administrator && user != UserType.SuperUser) || !UpdateDBTables()) { MessageBox.Show("Utente senza privilegi per l'upgrade"); return(false); } UpdateDBVersion(Module(), CurrentVersion()); } return(true); }
protected DataReaderUpdater(SqlProxyConnection conn, IDocumentBase documentBase) { System.Diagnostics.Debug.Assert(conn != null, "Connection is null"); myTable = typeof(TTable).GetField("Name").GetValue(null).ToString(); sqlCN = documentBase != null && documentBase.Connection != null ? documentBase.Connection : conn; this.documentBase = documentBase; }
/// <summary> /// ConnectToDatabase. /// Si connette ad un database esistente /// </summary> private bool ConnectToDatabase() { var connected = false; var connectionString = GetConnectionString(); try { myConnection = new SqlProxyConnection(connectionString); myConnection.Open(); connected = (myConnection.State == ConnectionState.Open); // @@ try to remove changedatabase //if (connected) // myConnection.ChangeDatabase(lI.InitialCatalog); } catch (System.Exception ex) { MessageBox.Show(ex.ToString(), GlobalInfo.LoginInfo.InitialCatalog, MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } if (SqlProxyDatabaseHelper.SearchTable <EF_Version>(myConnection)) { if (MessageBox.Show(Properties.Resources.Database_WrongType, Properties.Resources.Attention, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { connected = false; return(false); } else { RegisterModule RsT = new ERPFramework.ModuleData.RegisterModule(); RsT.CreateTable(myConnection, GlobalInfo.UserInfo.userType); AddAdminUser(); } } else { RegisterModule RsT = new ERPFramework.ModuleData.RegisterModule(); connected = RsT.CreateTable(myConnection, GlobalInfo.UserInfo.userType); } return(connected); }
/// <summary> /// NewConnection. /// Si connette ad un database esistente /// </summary> public SqlProxyConnection NewConnection() { SqlProxyConnection newConn = null; string connectionString = GetConnectionString(); try { newConn = new SqlProxyConnection(connectionString); newConn.Open(); if (newConn.State == ConnectionState.Open) { newConn.ChangeDatabase(GlobalInfo.LoginInfo.InitialCatalog); } } catch (System.Exception ex) { MessageBox.Show(ex.ToString(), GlobalInfo.LoginInfo.InitialCatalog, MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } return(newConn); }
/// <summary> /// CreateNewDatabase. /// Crea un nuovo database /// </summary> private bool CreateNewDatabase() { SqlProxyDatabaseHelper.DataSource = GlobalInfo.LoginInfo.DataSource; SqlProxyDatabaseHelper.UserID = GlobalInfo.LoginInfo.UserID; SqlProxyDatabaseHelper.Password = GlobalInfo.LoginInfo.Password; SqlProxyDatabaseHelper.InitialCatalog = GlobalInfo.LoginInfo.InitialCatalog; SqlProxyDatabaseHelper.IntegratedSecurity = GlobalInfo.LoginInfo.AuthenicationMode == AuthenticationMode.Windows; SqlProxyDatabaseHelper.CreateDatabase(); try { var connectionString = GetConnectionString(); myConnection = new SqlProxyConnection(connectionString); myConnection.Open(); if (myConnection.State == ConnectionState.Open) { MessageBox.Show(Properties.Resources.Database_Create, GlobalInfo.LoginInfo.InitialCatalog, MessageBoxButtons.OK, MessageBoxIcon.Information); } //myConnection.ChangeDatabase(GlobalInfo.LoginInfo.InitialCatalog); RegisterModule RsT = new ERPFramework.ModuleData.RegisterModule(); RsT.CreateTable(myConnection, GlobalInfo.UserInfo.userType); AddAdminUser(); } catch (System.Exception ex) { MessageBox.Show(ex.ToString(), GlobalInfo.LoginInfo.InitialCatalog, MessageBoxButtons.OK, MessageBoxIcon.Information); } if (myConnection.State == ConnectionState.Open) { myConnection.Clone(); } return(true); }
protected DataReaderUpdater(SqlProxyConnection conn, bool updater) : this(conn, null) { }