/// <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> /// 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); }