static public bool DatabaseExists(SBSystem system) { Server server = null; //string sys_auth_mode_dto_filename = "Resources/sys_auth_mode_dto.xml"; //SBSystem_DTO auth_dto = null; //if (File.Exists(sys_auth_mode_dto_filename)) //{ // using (XmlReader xmlRdr = new XmlTextReader(sys_auth_mode_dto_filename)) // { // auth_dto = (from sysElem in XDocument.Load(xmlRdr).Element("Systems").Elements("System") // select new SBSystem_DTO( // (string)sysElem.Attribute("Name"), // (string)sysElem.Attribute("Application") // )).FirstOrDefault(); // } //} //if (auth_dto.Name.Equals("True", StringComparison.CurrentCultureIgnoreCase)) //{ // string auto_complete_conn_info_filename = "Resources/auto_complete_conn_info_dto.xml"; // SBSystem_DCP_DTO dcp_dto = null; // if (File.Exists(auto_complete_conn_info_filename)) // { // using (XmlReader xmlRdr = new XmlTextReader(auto_complete_conn_info_filename)) // { // dcp_dto = (from sysElem in XDocument.Load(xmlRdr).Element("Systems").Elements("System") // select new SBSystem_DCP_DTO( // (string)sysElem.Attribute("Name"), // (string)sysElem.Attribute("Application"), // (string)sysElem.Attribute("Database"), // (bool)sysElem.Attribute("SName"), // (bool)sysElem.Attribute("UName"), // (bool)sysElem.Attribute("PName") // )).FirstOrDefault(); // } // ServerConnection srvConn = new ServerConnection(); // srvConn.ServerInstance = system.Server; // srvConn.LoginSecure = false; // if (dcp_dto.Application != null) // { // srvConn.Login = dcp_dto.Application; // } // if (dcp_dto.Application != null) // { // srvConn.Password = dcp_dto.Database; // } // server = new Server(srvConn); // } //} //else //{ server = new Server(system.Server); //} if (server == null) { return(false); } return(server.Databases.Contains(system.Database)); }
public SystemDetailsForm(SBSystem sbsystem) { InitializeComponent(); if (sbsystem == null) { throw new ArgumentNullException("sbsystem"); } sys = sbsystem; }
static public bool ServerExists(SBSystem system) { DataTable dt = SmoApplication.EnumAvailableSqlServers(true); bool exists = false; foreach (DataRow dr in dt.Rows) { string name = dr["Name"].ToString().Trim(); string server = dr["Server"].ToString().Trim(); string Instance = dr["Instance"].ToString().Trim(); exists = name.ToUpper().Equals(system.Server.Trim().ToUpper()); } return(exists); }
public LoginForm(SBSystem defsys) { InitializeComponent(); this.txtUserName.Focus(); _SBsystems = GetDataFromXML(); cbSystems.DataSource = _SBsystems; cbSystems.DisplayMember = "Name"; cbSystems.ValueMember = "Name"; cbSystems.SelectedValue = defsys.Name; if (defsys != null) { _defaultsys = defsys; } }
static public string EntityConnection(SBSystem system, string userId, string Pwd, bool IntegratedSec) { // Specify the provider name, server and database. string providerName = "System.Data.SqlClient"; string serverName = system.Server; string databaseName = system.Database; // Initialize the connection string builder for the // underlying provider. SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(); // Set the properties for the data source. sqlBuilder.DataSource = serverName; sqlBuilder.InitialCatalog = databaseName; sqlBuilder.IntegratedSecurity = IntegratedSec; sqlBuilder.UserID = userId; sqlBuilder.Password = Pwd; // Build the SqlConnection connection string. string providerString = sqlBuilder.ToString(); // Initialize the EntityConnectionStringBuilder. EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(); //Set the provider name. entityBuilder.Provider = providerName; // Set the provider-specific connection string. entityBuilder.ProviderConnectionString = providerString; // Set the Metadata location. string metadata = @"res://*/SBPayrollDBEntities.csdl|res://*/SBPayrollDBEntities.ssdl|res://*/SBPayrollDBEntities.msl"; metadata.Replace("SBPayrollDBEntities", system.Metadata); entityBuilder.Metadata = metadata; return(entityBuilder.ToString()); }
static public string DatabaseVersion(SBSystem system) { if (!DatabaseExists(system)) { throw new ArgumentException("Database " + system.Database + " does not exist" + "\n\n " + "Do you want to Administer Servers and Databases?", "database"); } Server server = new Server(system.Server); string DatabaseVersionExtPropertyKey = system.Application.Trim() + "Version"; Database db = server.Databases[system.Database]; var sbverion = db.ExtendedProperties[DatabaseVersionExtPropertyKey]; if (sbverion == null) { throw new ArgumentException(" A database named [" + system.Database + "] exists but does not contain Version information which is neccessary for the System [" + system.Application + "] " + "\n\n " + "Do you want to Administer Servers and Databases?", "version"); } return(sbverion.Value.ToString()); }
static public string EntityConnection(SBSystem system) { return(EntityConnection(system, "", "", true)); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { SplashScreen.ShowSplashScreen(); Application.DoEvents(); SplashScreen.SetStatus("Checking for [ " + SystemsConfigFile + " ] ..."); if (!File.Exists(SystemsConfigFile)) { throw new FileNotFoundException("SB Payroll cannot locate configuration file " + SystemsConfigFile); } SplashScreen.SetStatus("Checking for Default System..."); SBSystem defSys = SQLHelper.GetDataDefaultSystem(); if (defSys == null) { throw new ArgumentException("No Default System is Set", "system"); } //SplashScreen.SetStatus("Connecting to the SQL Server [" + defSys.Server + "]"); //if (!SQLHelper.ServerExists(defSys)) // throw new ArgumentException("Unable to connect to Server [" + defSys.Server + "] ", "server"); SplashScreen.SetStatus("Checking for a valid Database..."); if (!SQLHelper.DatabaseExists(defSys)) { throw new ArgumentException("Database [ " + defSys.Database + " ] does not exist in Server [ " + defSys.Server + " ] ", "database"); } SplashScreen.SetStatus("Checking for Database Version..."); string dbver = SQLHelper.DatabaseVersion(defSys); string sysver = Assembly.GetEntryAssembly().GetName().Version.ToString(); if (!dbver.Equals(sysver)) { throw new ArgumentException("Database and System Version do not match; the Database may not be usable. Use a Database Migration Tool", "version"); } SplashScreen.SetStatus("Checking Defaults Tables are populated..."); System.Threading.Thread.Sleep(400); SplashScreen.SetStatus("Checking for a valid License..."); System.Threading.Thread.Sleep(2000); SplashScreen.CloseForm(); Application.Run(new Forms.LoginForm(defSys)); } catch (ArgumentException argex) { string msgex = string.Empty; if (argex.ParamName.Equals("server") || argex.ParamName.Equals("system") || argex.ParamName.Equals("database") || argex.ParamName.Equals("version")) { switch (argex.ParamName) { case "system": msgex = "Do you want to search other Servers ?"; break; case "server": msgex = "The default Server does not exist. Do you want to search for other Servers ?"; break; case "database": msgex = "Do you want to create a Database ?"; break; case "version": msgex = "Do you want to create a Database with current Version ?"; break; } string msg = argex.Message; if (argex.InnerException != null) { msg += "\n" + argex.InnerException.Message; } msg += "\n\n " + msgex; if (DialogResult.Yes == MessageBox.Show(msg, "SB Payroll", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { Forms.DatabaseControlPanelForm f = new DatabaseControlPanelForm(); f.ShowDialog(); } } } catch (Microsoft.SqlServer.Management.Common.ConnectionFailureException smoex ) { string msg = smoex.Message; if (smoex.InnerException != null) { msg += "\n" + smoex.InnerException.Message + "\n\n " + "Do you want to Administer Servers and Databases ?"; } if (DialogResult.Yes == MessageBox.Show(msg, "SB Payroll", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { Forms.DatabaseControlPanelForm f = new DatabaseControlPanelForm(); f.ShowDialog(); } } catch (Exception ex) { string msg = ex.Message; if (ex.InnerException != null) { msg += "\n" + ex.InnerException.Message + "\n\n " + "Do you want to Administer Servers and Databases ?"; } if (DialogResult.Yes == MessageBox.Show(msg, "SB Payroll", MessageBoxButtons.YesNo, MessageBoxIcon.Information)) { Forms.DatabaseControlPanelForm f = new DatabaseControlPanelForm(); f.ShowDialog(); } } }