• 操作MSSQL服务还有测试是否连接


           private void btnOk_Click(object sender, EventArgs e)
            {
                IList<string> _DataBaseList = new List<string>();
                System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController();
                sc.ServiceName = "MSSQLSERVER";
                if (sc == null)
                {
                    MessageBox.Show("您的机器上没有安装SQL SERVER!", "提示信息");
                    return;
                }
                else if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Running)
                {
                    MessageBox.Show("SQL数据库服务未启动,请点击开启SQL服务!", "提示信息");
                    return;
                }
                //_DBConfig = new DBConfig();
                if (cboServerName.Text == "Local(本机)")
                {
                    _DBConfig.ServerName = "(local)";
                }
                else
                {
                    _DBConfig.ServerName = cboServerName.Text.ToString();
                }
                if (cboValidataType.Text == "Windows身份认证")
                {
                    _DBConfig.ValidataType = "Windows身份认证";
                }
                else
                {
                    txtPassword.Enabled = true;
                    txtUser.Enabled = true;
                    _DBConfig.ValidataType = "SQL Server身份认证";
                    _DBConfig.UserName = txtUser.Text.ToString();
                    _DBConfig.UserPwd = txtPassword.Text.ToString();

                }
                _conString = GetSQLmasterConstring(_DBConfig);
                _DBConfig.DB = new DBUtility.DbHelperSQL(_conString);
                _DataBaseList = _DBConfig.DB.GetDataBaseInfo();
                if (_DataBaseList.Count > 0)
                {
                    cboDataBase.DataSource = _DataBaseList;
                    cboDataBase.Enabled = true;
                    cboDataBase.SelectedIndex = 0;
                }
                else
                {
                    cboDataBase.Enabled = false;
                    cboDataBase.Text = "";
                    cboDataBase.DataSource = null;
                }

  • 相关阅读:
    分布式锁的几种实现方式
    分布式锁简单入门以及三种实现方式介绍
    Redis 总结精讲
    Redis 总结精讲 看一篇成高手系统-4
    Request、Response 之 Http 请求
    定时任务 Cron表达式
    跑批利器--批处理应用程序
    使用MultiByteToWideChar转换UTF8为GBK(UTF8在Windows的代码页是CP_UTF8)
    了解 XML 数字签名
    QuickReport根据每行的内容长度动态调整DetailBand1的行高
  • 原文地址:https://www.cnblogs.com/wujy/p/2510824.html
Copyright © 2020-2023  润新知