public static SEGURIDAD_SUPERMERCADOEntities ObtenerInstancia() { ArchivoBaseDeDatos(); // Specify the provider name, server and database. string providerName = "System.Data.SqlClient"; // Initialize the connection string builder for the // underlying provider. SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(); // Set the properties for the data source. sqlBuilder.DataSource = serverName; sqlBuilder.InitialCatalog = databaseName; sqlBuilder.UserID = UserID; sqlBuilder.Password = Password; sqlBuilder.IntegratedSecurity = false; sqlBuilder.MultipleActiveResultSets = true; sqlBuilder.UserInstance = false; // Build the SqlConnection connection string. string providerString = sqlBuilder.ToString(); // Initialize the EntityConnectionStringBuilder. EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(); //Set the provider name. entityBuilder.Provider = providerName; // Set the provider-specific connection string. entityBuilder.ProviderConnectionString = providerString; // Set the Metadata location. SIST_SUPERMERCADO entityBuilder.Metadata = @"res://*/" + Contexto + ".csdl|res://*/" + Contexto + ".ssdl|res://*/" + Contexto + ".msl"; EntityConnection conn = new EntityConnection(entityBuilder.ToString()); _instancia = new SEGURIDAD_SUPERMERCADOEntities(conn); StringConexion = entityBuilder.ProviderConnectionString; return _instancia; }
private void btnTEST_Click(object sender, EventArgs e) { // Specify the provider name, server and database. string providerName = "System.Data.SqlClient"; string serverName = txtSERVIDOR.Text; //"localhost"; string databaseName = txtBASEDATOS.Text; //"SIST_SUPERMERCADO"; // Initialize the connection string builder for the // underlying provider. SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(); // Set the properties for the data source. sqlBuilder.DataSource = serverName; sqlBuilder.InitialCatalog = databaseName; sqlBuilder.UserID = txtUSUARIO.Text; //"sa"; sqlBuilder.Password = txtCONTRASEÑA.Text; //"26639639"; sqlBuilder.IntegratedSecurity = true; sqlBuilder.MultipleActiveResultSets = true; // Build the SqlConnection connection string. string providerString = sqlBuilder.ToString(); // Initialize the EntityConnectionStringBuilder. EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(); //Set the provider name. entityBuilder.Provider = providerName; // Set the provider-specific connection string. entityBuilder.ProviderConnectionString = providerString; // Set the Metadata location. SIST_SUPERMERCADO entityBuilder.Metadata = @"res://*/" + txtCONTEXTO.Text + ".csdl|res://*/" + txtCONTEXTO.Text + ".ssdl|res://*/" + txtCONTEXTO.Text + ".msl"; EntityConnection conn = new EntityConnection(entityBuilder.ToString()); switch (txtBASEDATOS.Text) { case "SIST_SUPERMERCADO": var instancia = new SIST_SUPERMERCADOEntities(conn); if (instancia != null) { MostrarMensajeInformativo("La conexión a la base de datos se realizó con éxito."); } else { MostrarMensajeInformativo("No se realió la conexión a la base de datos."); } break; case "SEGURIDAD_SUPERMERCADO": var instancia1 = new SEGURIDAD_SUPERMERCADOEntities(conn); if (instancia1 != null) { MostrarMensajeInformativo("La conexión a la base de datos se realizó con éxito."); } else { MostrarMensajeInformativo("No se realió la conexión a la base de datos."); } break; case "AUDITORIA": var instancia2 = new AUDITORIAEntities(conn); if (instancia2 != null) { MostrarMensajeInformativo("La conexión a la base de datos se realizó con éxito."); } else { MostrarMensajeInformativo("No se realió la conexión a la base de datos."); } break; } }
private mFORMULARIO() { ctx = SEGURIDAD_SUPERMERCADOEntities.ObtenerInstancia(); }