private void startModeSetting(ref UserInfoBo userInfo, Login form) { CommonFunction common = new CommonFunction(); if (form.kojinRdo.Checked) { common.setSqliteDbContextPath(WordConverter_v2.Settings1.Default.SqliteContextString); userInfo.startUpMode = (int)StartUpMode.個人; } else { StringBuilder sb = new StringBuilder(); sb.Append("Server=" + WordConverter_v2.Settings1.Default.ServerName); sb.Append(";Port=" + WordConverter_v2.Settings1.Default.DbPortNo); sb.Append(";User Id=" + WordConverter_v2.Settings1.Default.DbUserId); sb.Append(";Password="******";Database=" + WordConverter_v2.Settings1.Default.DbName); common.setPostgresDbContext(sb.ToString()); userInfo.startUpMode = (int)StartUpMode.複数人; } }
private void sqliteTestConnectBtn_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append("Data Source=" + this.sqliteDbFilePath.Text); sb.Append(";foreign keys=true;"); CommonFunction common = new CommonFunction(); string dbConnectionString = common.getDbConnectionString(); string dbProviderName = common.getDbProviderName(); try { using (SQLiteConnection cn = new SQLiteConnection(sb.ToString())) { cn.Open(); SQLiteCommand cmd = cn.CreateCommand(); cmd.CommandText = "SELECT * FROM WORD_DIC"; cmd.ExecuteReader(); common.setSqliteDbContextPath(sb.ToString()); MyRepository rep = new MyRepository(); UserMst fromUser = rep.FindUserMstByUserId(999); MessageBox.Show("DB接続に成功しました!!"); this.sqliteConnectableDbPath.Text = sb.ToString(); this.sqliteSaveBtn.Visible = true; this.sqliteDbFilePath.Enabled = false; } } catch (Exception ex) { MessageBox.Show("DB接続失敗"); common.resetDbContextPath(dbConnectionString, dbProviderName); } }