示例#1
0
        /// <summary>
        /// will return current SQL Connector was connected to MS SQL or My SQL or SQLite DB
        /// </summary>
        /// <param name="settings">ISQLConnectionSettings</param>
        public static SqlAbstractConnector SetConnector(ISQLConnectionSettings settings)
        {
            SqlAbstractConnector sqlConnector = null;

            switch (settings.ProviderName)
            {
            case SQLProvider.SQLite:
            {
                sqlConnector = new SQLiteModelDBOperations(settings);
                break;
            }

            case SQLProvider.My_SQL:
            {
                sqlConnector = new MySQLUtils(settings);
                break;
            }

            case SQLProvider.MS_SQL:
            {
                sqlConnector = new MsSqlUtils(settings);
                break;
            }
            }
            return(sqlConnector);
        }
示例#2
0
        private ISQLConnectionSettings CheckMSSQLDB(ISQLConnectionSettings tmpSettings)
        {
            ISQLConnectionSettings newSettings = MakeFromControls(tmpSettings, "");

            MsSqlUtils msSQL = new MsSqlUtils(newSettings);

            try
            {
                using (DataTable dt = msSQL.GetTable("SELECT Name FROM sys.databases", 5))
                {
                    tbResultShow.AppendLine(msSQL.GetConnection().ToString());
                    tbResultShow.AppendLine("Строка подключения: " + msSQL.connString);

                    if (dt?.Rows?.Count > 0)
                    {
                        IList <string> list = new List <string>();
                        foreach (DataRow r in dt.Rows)
                        {
                            list.Add(r[0].ToString());
                        }

                        if (list?.Count > 0)
                        {
                            cmbDataBases.DataSource = list;
                            cmbDataBases.Enabled    = true;
                            newSettings.Database    = list[0];

                            tbResultShow.AppendLine("The inputed data are correct.");
                        }
                    }
                    else
                    {
                        tbResultShow.AppendLine("Указаны некорректны данные или отсутствует подключение к серверу!");
                    }
                }
            }
            catch (Exception excpt)
            {
                newSettings = null;
                tbResultShow.AppendLine(excpt.Message + ":");
                tbResultShow.AppendLine(excpt.ToString());
            }

            return(newSettings);
        }