public static int ConnectDatabase(string Datasource, string UserId, string Pass, string Database) { QuanLyKhoDongLucEntities db = new QuanLyKhoDongLucEntities(); db.Database.Connection.ConnectionString = "data source=" + Datasource + ";initial catalog=" + Database + ";persist security info=True;user id=" + UserId + ";password="******";MultipleActiveResultSets=True;"; try { db.Database.Connection.Open(); return(1); } catch (Exception) { return(0); } }
private void frmTonKho_Load(object sender, EventArgs e) { var db = new QuanLyKhoDongLucEntities(); dtFrom.DateTime = DateTime.Now - TimeSpan.FromDays(30); dtTo.DateTime = DateTime.Now; if (ID_ton_dau_ky != 0) { var tondauky = db.STO_TonDauKy.First(t => t.ID_ton == ID_ton_dau_ky); if (tondauky != null) { ledKhoVT.EditValue = tondauky.ID_kho; ledTonDauKy.EditValue = tondauky.ID_ton; } } }
public static List <string> GetDatabaseList(string Datasource, string UserId, string Pass) { string connectionString = "Data Source=" + Datasource + ";Initial Catalog=master;Persist Security Info=True;User ID=" + UserId + ";Password="******";MultipleActiveResultSets=True;"; QuanLyKhoDongLucEntities db = new QuanLyKhoDongLucEntities(); db.Database.Connection.ConnectionString = connectionString; try { var databases = db.Database.SqlQuery <string>("SELECT [name] FROM sys.databases where [name] = 'QuanLyKhoDongLuc'").ToList(); return(databases); } catch { return(new List <string>()); } }