コード例 #1
0
ファイル: frmConnect.cs プロジェクト: sillsdev/FwSupportTools
        private void cmdOK_Click(object sender, System.EventArgs e)
        {
            string sConnectionString;
            string sUsername;
            string sServer   = cboServer.Text;
            string sDatabase = "";

            RegistryKey oKey = null;

            try
            {
                oKey = Registry.CurrentUser.OpenSubKey(Globals.ksRegKeyRoot + @"\Databases");
                if (oKey != null)
                {
                    string sLocalServer = SystemInformation.ComputerName.ToLower();
                    sDatabase = oKey.GetValue(sServer.ToLower().Replace(sLocalServer, "."), "").ToString();
                    if (sDatabase.Length == 0 && sServer.IndexOf(".") != -1)
                    {
                        // Try it with the actual name of the machine instead of the "."
                        sDatabase = oKey.GetValue(sServer.Replace(".", sLocalServer), "").ToString();
                    }
                }
            }
            finally
            {
                if (oKey != null)
                {
                    oKey.Close();
                }
            }

            sServer = sServer.Replace(".", SystemInformation.ComputerName);

            if (optWindows.Checked)
            {
                sUsername         = SystemInformation.UserDomainName + "\\" + SystemInformation.UserName;
                sConnectionString =
                    "Data Source=" + sServer + ";" +
                    "Integrated Security=SSPI";
            }
            else
            {
                sUsername         = txtUsername.Text;
                sConnectionString =
                    "Data Source=" + sServer + ";" +
                    "User Id=" + sUsername + ";" +
                    "Password=" + txtPassword.Text;
            }

            if (Globals.OpenConnection(this, sUsername, sServer,
                                       sConnectionString, chkAutoStart.Checked, sDatabase))
            {
                SaveLastServers();
                this.Close();
            }
        }
コード例 #2
0
 public void DoNew()
 {
     Globals.OpenConnection(this, m_sUsername, m_oConn.DataSource,
                            m_oConn.ConnectionString, false, m_oConn.Database);
 }