/// <summary>
        /// Writes the database to the location defined in the configuration file if it doesn't exist.
        /// </summary>
        public static void CheckForDatabase()
        {
            // A LocalSqlServer connection string get's added by default. Don't look at that one.
            foreach (ConnectionStringSettings connection in ConfigurationManager.ConnectionStrings.OfType<ConnectionStringSettings>().Where(c => c.Name != "LocalSqlServer"))
            {
                try
                {
                    EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder(connection.ConnectionString);
                    SqlCeConnectionStringBuilder sqlCEBuilder = new SqlCeConnectionStringBuilder(builder.ProviderConnectionString);

                    if (!File.Exists(sqlCEBuilder.DataSource))
                    {
                        FileInfo info = new FileInfo(sqlCEBuilder.DataSource);

                        if (!Directory.Exists(info.Directory.FullName))
                        {
                            Directory.CreateDirectory(info.Directory.FullName);
                        }

                        File.WriteAllBytes(info.FullName, EncounterTracker.Properties.Resources.EncounterTracker);
                    }

                    break;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 2
0
        public static void InitDatabase(string hostname, string username, string password, string database)
        {
            if (!IsNullOrEmpty(m_ConnectionString))
                return;

            //Build an SQL connection string
            var sqlString = new SqlConnectionStringBuilder()
            {
                DataSource = hostname,
                InitialCatalog = database,
                UserID = username,
                Password = password,
                ApplicationName = "EntityFramework",
                MultipleActiveResultSets = true,
                PersistSecurityInfo = true
            };

            //Build an entity framework connection string
            var entityString = new EntityConnectionStringBuilder()
            {
                Provider = "System.Data.SqlClient",
                Metadata = "res://*/BluffinMuffinLogs.csdl|res://*/BluffinMuffinLogs.ssdl|res://*/BluffinMuffinLogs.msl",
                ProviderConnectionString = sqlString.ToString()
            };

            m_ConnectionString = entityString.ToString();
            Task.Factory.StartNew(LogCommands);
        }
Exemplo n.º 3
0
        public static string BuildEntityConnection1(string connString)
        {
            Type   t = typeof(Contex);
            string assemblyFullName = t.Assembly.FullName.ToString();

            string connectionString = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder

            {
                Provider = "System.Data.SqlClient",

                //Metadata = string.Format("res://{0}/", //Models.Model.csdl|Models.Model.ssdl|Models.Model.msl",
                //          assemblyFullName),



                ProviderConnectionString = new System.Data.SqlClient.SqlConnectionStringBuilder

                {
                    InitialCatalog = "NortPersonel",

                    //    DataSource = "192.168.0.17\\sql2014",
                    DataSource         = connString,
                    IntegratedSecurity = true,

                    ApplicationName = "Contex",
                    UserID          = "sa", // User ID such as "sa"

                    Password = "******",      // hide the password
                }.ConnectionString
            }.ConnectionString;

            return(connectionString);
        }
        // ctx.Database.Connection.ConnectionString strips the password, not useful in Azure
        // Therefore we have to use the builder
        public string GetProviderConnectionString()
        {
            string efConnectionString = ConfigurationManager.ConnectionStrings["RftContext"].ConnectionString;

            var builder = new EntityConnectionStringBuilder(efConnectionString);
            return builder.ProviderConnectionString;
        }
        public static string Connect()
        {
            string conString = ConfigurationManager.ConnectionStrings["YourConnectionStringsName"].ConnectionString;

            if (conString.ToLower().StartsWith("metadata="))
            {
                System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder efBuilder = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(conString);
                conString = efBuilder.ProviderConnectionString;
            }
            SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);
            string dataSource = cns.DataSource;
            SqlConnectionStringBuilder sqlString = new SqlConnectionStringBuilder()
            {
                DataSource               = cns.DataSource,        // Server name
                InitialCatalog           = cns.InitialCatalog,    //Database
                UserID                   = cns.UserID,            //Username
                Password                 = cns.Password,          //Password,
                MultipleActiveResultSets = true,
                ApplicationName          = "EntityFramework",
            };
            //Build an Entity Framework connection string
            EntityConnectionStringBuilder entityString = new EntityConnectionStringBuilder()
            {
                Provider = "System.Data.SqlClient",
                Metadata = "res://*",
                ProviderConnectionString = sqlString.ToString()
            };

            return(entityString.ConnectionString);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Builds an entity framework connection string
        /// </summary>
        /// <param name="ServerName">Server Name</param>
        /// <param name="DatabaseName">Database Name</param>
        /// <returns>connection string to use</returns>
        public static string BuildConnectionString(string ServerName, string DatabaseName)
        {
            // Initialize the connection string builder for the
            // underlying provider.
            var Builder = new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            Builder.DataSource = ServerName;
            Builder.InitialCatalog = DatabaseName;
            Builder.IntegratedSecurity = true;

            // Initialize the EntityConnectionStringBuilder.
            var EntityStringBuilder = new EntityConnectionStringBuilder();

            //Set the provider name.
            EntityStringBuilder.Provider = "System.Data.SqlClient";

            // Set the provider-specific connection string.
            EntityStringBuilder.ProviderConnectionString = Builder.ToString();

            // Set the Metadata location.
            EntityStringBuilder.Metadata = "res://*/";

            //return the string now
            return EntityStringBuilder.ToString();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets the context.
        /// </summary>
        /// <returns></returns>
        public static Apps4KidsEntities GetContext()
        {
            Apps4KidsEntities result;

            if (connectionString != null)
            {
                return new Apps4KidsEntities(connectionString);
            }

            EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder();

            SqlConnectionStringBuilder sqlcsb = new SqlConnectionStringBuilder();

            ecsb.Metadata = @"res://*/DataModel.csdl|
                            res://*/DataModel.ssdl|
                            res://*/DataModel.msl";

            ecsb.Provider = "System.Data.SqlClient";

            sqlcsb.InitialCatalog = "Apps4Kids";
            sqlcsb.DataSource = "localhost";
            sqlcsb.UserID = "sa";
            sqlcsb.Password = "******";

            ecsb.ProviderConnectionString = sqlcsb.ToString();

            result = new Apps4KidsEntities(ecsb.ConnectionString);
            return result;
        }
Exemplo n.º 8
0
 public static string ConvertEFConnStringToSQLProviderConnString(string entityConnString)
 {
     var efBuilder = new EntityConnectionStringBuilder(entityConnString);
     var sqlBuilder = new SqlConnectionStringBuilder(efBuilder.ProviderConnectionString);
     sqlBuilder.ApplicationName = null;
     return sqlBuilder.ConnectionString;
 }
Exemplo n.º 9
0
        private static string ExtractConnectionStringFromEntityConnectionString(string entityConnectionString)
        {
            // create a entity connection string from the input
            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(entityConnectionString);

            // read the db connectionstring
            return entityBuilder.ProviderConnectionString;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Método que obtiene la cadena de 
 /// conexión para MySQL
 /// </summary>
 /// <param name="Key">nombre de la llave que contiene la estructura de la BD</param>
 /// <returns>cadena de caracteres de la cadena de conexión.</returns>
 public static string ObtieneConexionMySqlEf(string Key)
 {
     string connectionString = Conexion.GetConnectionString(Key);
     MySqlConnectionStringBuilder mysqlsbc = new MySqlConnectionStringBuilder(connectionString);
     EntityConnectionStringBuilder ecb = new EntityConnectionStringBuilder();
     ecb.Metadata = "res://*/MySQL.MymEf.EventoSocial.csdl|res://*/MySQL.MymEf.EventoSocial.ssdl|res://*/MySQL.MymEf.EventoSocial.msl";
     ecb.Provider = "MySql.Data.MySqlClient";
     ecb.ProviderConnectionString = mysqlsbc.ConnectionString;
     return ecb.ConnectionString;
 }
Exemplo n.º 11
0
        public static string BuildEntityConnectionString(string connectionString, string modelName)
        {
            var builder = new EntityConnectionStringBuilder
            {
                Metadata = string.Format("res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", modelName),
                Provider = "System.Data.SqlClient",
                ProviderConnectionString = connectionString
            };

            return builder.ToString();
        }
Exemplo n.º 12
0
 public ConnectUpdate()
 {
     this.db = new hackathonunitecEntities();
     string originalConnectionString = ConfigurationManager.ConnectionStrings["hackathonunitecEntities"].ConnectionString;
     EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(originalConnectionString);
     DbProviderFactory factory = DbProviderFactories.GetFactory(entityBuilder.Provider);
     DbConnectionStringBuilder providerBuilder = factory.CreateConnectionStringBuilder();
     providerBuilder.ConnectionString = entityBuilder.ProviderConnectionString;
     providerBuilder.Add("Password", "JDCR7EpaEt5TQnE6");
     this.db.Database.Connection.ConnectionString = providerBuilder.ConnectionString;
 }
Exemplo n.º 13
0
        public WesterosDataAccess(string connectionStringKey = "westerosConnectionString")
        {
            var contextConnectionString = GetContextConnectionString(connectionStringKey);

            if (string.IsNullOrEmpty(_connectionString))
                throw new Exception("Unable to find a connection string");

            var ecsb = new EntityConnectionStringBuilder(contextConnectionString);

            Context = new DataContext(ecsb.ConnectionString);
        }
Exemplo n.º 14
0
        public static void SetConString()
        {
            DBConnectioin oDbConn = new DBConnectioin();
            ConString = oDbConn.GetConString();

            var Orig = System.Configuration.ConfigurationManager.ConnectionStrings["AspetProdEntities"].ConnectionString;
            var ecs = new EntityConnectionStringBuilder(Orig);
            ecs.ProviderConnectionString = ConString;
            ConString = ecs.ToString();
             //   return bValidLogin;
        }
Exemplo n.º 15
0
        public static string GetEFConnectionString(DALISGDatabaseType databaseType)
        {
            var entityConnectionStringBuilder =
                new EntityConnectionStringBuilder
                {
                    Provider = "System.Data.SqlClient",
                    ProviderConnectionString = GetConnectionString(databaseType),
                    Metadata = GetEFConnectionStringMetadata(databaseType)
                };

            return entityConnectionStringBuilder.ToString();
        }
Exemplo n.º 16
0
        public static string TradeConnectionString(string sqlConString
            )
        {
            var entityBuilder = new EntityConnectionStringBuilder
            {
                Provider = "System.Data.SqlClient",
                ProviderConnectionString = sqlConString,
                Metadata = @"res://*/Trade.csdl|res://*/Trade.ssdl|res://*/Trade.msl"
            };

            return entityBuilder.ToString();
        }
Exemplo n.º 17
0
     public Entities()
         : base("name=Entities")
     {
 		var originalConnectionString = ConfigurationManager.ConnectionStrings["Entities"].ConnectionString;
         var entityBuilder = new EntityConnectionStringBuilder(originalConnectionString);
         var factory = DbProviderFactories.GetFactory(entityBuilder.Provider);
         var providerBuilder = factory.CreateConnectionStringBuilder();
 		providerBuilder.ConnectionString = entityBuilder.ProviderConnectionString;
 		providerBuilder.Add("Password", "qwer1234");
 		entityBuilder.ProviderConnectionString = providerBuilder.ToString();
 		this.Database.Connection.ConnectionString = entityBuilder.ProviderConnectionString;
     }
Exemplo n.º 18
0
        // all params are optional
        public static void ChangeDatabase(
            this DbContext source,
            string initialCatalog = "",
            string dataSource = "",
            string userId = "",
            string password = "",
            bool integratedSecuity = true,
            string configConnectionStringName = "")
        /* this would be used if the
        *  connectionString name varied from 
        *  the base EF class name */
        {
            try
            {
                // use the const name if it's not null, otherwise
                // using the convention of connection string = EF contextname
                // grab the type name and we're done
                var configNameEf = string.IsNullOrEmpty(configConnectionStringName)
                    ? source.GetType().Name
                    : configConnectionStringName;

                // add a reference to System.Configuration
                var entityCnxStringBuilder = new EntityConnectionStringBuilder
                    (System.Configuration.ConfigurationManager
                        .ConnectionStrings[configNameEf].ConnectionString);

                // init the sqlbuilder with the full EF connectionstring cargo
                var sqlCnxStringBuilder = new SqlConnectionStringBuilder
                    (entityCnxStringBuilder.ProviderConnectionString);

                // only populate parameters with values if added
                if (!string.IsNullOrEmpty(initialCatalog))
                    sqlCnxStringBuilder.InitialCatalog = initialCatalog;
                if (!string.IsNullOrEmpty(dataSource))
                    sqlCnxStringBuilder.DataSource = dataSource;
                if (!string.IsNullOrEmpty(userId))
                    sqlCnxStringBuilder.UserID = userId;
                if (!string.IsNullOrEmpty(password))
                    sqlCnxStringBuilder.Password = password;

                // set the integrated security status
                sqlCnxStringBuilder.IntegratedSecurity = integratedSecuity;

                // now flip the properties that were changed
                source.Database.Connection.ConnectionString
                    = sqlCnxStringBuilder.ConnectionString;
            }
            catch (Exception ex)
            {
                // set log item if required
            }
        }
        public static string ToEntityFrameworkConnectionString(this string sqlConnectionString, string metaData)
        {
            const string providerName = "System.Data.SqlClient";

            var efBuilder = new EntityConnectionStringBuilder
            {
                Metadata = metaData,
                Provider = providerName,
                ProviderConnectionString = sqlConnectionString
            };

            return efBuilder.ConnectionString;
        }
        public static CostcoDevStatusEntities Create(string providerConnectionString)
        {
            var entityBuilder = new EntityConnectionStringBuilder();

            // use your ADO.NET connection string
            entityBuilder.ProviderConnectionString = providerConnectionString;

            entityBuilder.Provider = "System.Data.SqlClient";

            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/";

            return new CostcoDevStatusEntities(entityBuilder.ConnectionString);
        }
 void generateEntities()  //use connection param to modify the connection string and dbcontext;
 {  //to continue
     string ip = this.ServerIp;
     string username = this.ServerUsername;
     string password = this.ServerPassword;
     //Data Source=192.168.28.129;Initial Catalog=Dblibrary;Persist Security Info=True;User ID=sa;Password=19831122
     String sqlConnectionString = "Data Source=" + ServerIp + ";Initial Catalog=Location;Persist Security Info=True;User ID=" + ServerUsername + ";Password="******"res://*/Models.Location.csdl|res://*/Models.Location.ssdl|res://*/Models.Location.msl";
     eb.Provider = "System.Data.SqlClient";
     eb.ProviderConnectionString = sqlConnectionString;
     this.entitiesConnectionString=eb.ToString();
     this.dbEntities = new LocationEntities(this.entitiesConnectionString);
 }
Exemplo n.º 22
0
 public static string Connect()
 {
     var connectData = JsonConvert.DeserializeObject<Dictionary<string, string>>();
     var connect = new SqlConnectionStringBuilder
     {
         DataSource = connectData["server"],
         InitialCatalog = ConnectString["database"],
         UserID = connectData["username"],
         Password = connectData["password"]
     };
     var entityString = new EntityConnectionStringBuilder
     {
         Provider = connectData["provider"],
     }
 }
Exemplo n.º 23
0
        public static string CreateEFConnectionString(string sqlProviderConnectionString)
        {
            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
            //Set the provider name.
            entityBuilder.Provider = "System.Data.SqlClient";
            //entityBuilder.Provider = "System.Data.EntityClient";
            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = sqlProviderConnectionString;

            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/RTSModel.csdl|res://*/RTSModel.ssdl|res://*/RTSModel.msl";
            string efConnectionString = entityBuilder.ConnectionString;
            return efConnectionString;
        }
Exemplo n.º 24
0
        public static string ToEntityConnectionString(this string val, string contextName)
        {
            var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[val];
            if (connectionString == null)
            {
                throw new Exception("No ConnectionString   with name:" + val);
            }

            var entityBuilder = new EntityConnectionStringBuilder();

            entityBuilder.Provider = connectionString.ProviderName;
            entityBuilder.ProviderConnectionString = connectionString.ConnectionString;
            entityBuilder.Metadata = String.Format(MetadataPattern, contextName);
            return entityBuilder.ToString();
        }
        protected void EstablishEFConnection()
        {
            if (dataContext == null)
            {
                var entityBuilder = new EntityConnectionStringBuilder(ConfigurationManager.ConnectionStrings[connectionStringEF].ConnectionString);
                var providerBuilder = DbProviderFactories.GetFactory(entityBuilder.Provider).CreateConnectionStringBuilder();
                providerBuilder.ConnectionString = entityBuilder.ProviderConnectionString;
                providerBuilder.Add("Password", sqlLoginPassword);

                entityBuilder.ProviderConnectionString = providerBuilder.ToString();

                dataContext = new FinanceMonitorEntities(entityBuilder.ToString());
                //using System.Data.Entity.Core.Objects;
                //for error on next page zzz
            }
        }
Exemplo n.º 26
0
        private static MangosTExEntities GetContext(uint timeout = 15)
        {
            // retrieve entity ConnectionString from configuration file
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["MangosTExEntities"];
            // parsing entity ConnectionString
            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder(settings.ConnectionString);
            // using settings to create a ProviderConnectionString for MySql
            MySqlConnectionStringBuilder mysqlBuilder = new MySqlConnectionStringBuilder();
            mysqlBuilder.ConnectionTimeout = timeout;
            //mysqlBuilder.Server = Settings.DatabaseHost;
            //mysqlBuilder.Port = Settings.DatabasePort;

            // setting up ProviderConnectionString in entity ConnectionString
            entityBuilder.ProviderConnectionString = mysqlBuilder.ConnectionString;
            // create the DbContext using ConnectionString
            return new MangosTExEntities(entityBuilder.ConnectionString);
        }
        public string BuildEntityConnectionString(string sqlConnectionString)
        {
            EntityConnectionStringBuilder entityConnectionStringBuilder = new EntityConnectionStringBuilder();

            // Hard-code the provider name (since we only have a SQL Server source)
            entityConnectionStringBuilder.Provider = "System.Data.SqlClient";

            // Set the provider-specific connection string
            entityConnectionStringBuilder.ProviderConnectionString =
                new SqlConnectionStringBuilder(sqlConnectionString).ToString();

            // Set the resource metadata location
            entityConnectionStringBuilder.Metadata =
                "res://*/ExperimentModel.csdl|res://*/ExperimentModel.ssdl|res://*/ExperimentModel.msl";

            return entityConnectionStringBuilder.ToString();
        }
Exemplo n.º 28
0
        public static string GetDB0EntityString(string configstring)
        {
            string[] DataConnectionInfo = configstring.Split(',');

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
            builder.DataSource = DataConnectionInfo[0];
            builder.UserID = DataConnectionInfo[1];
            builder.Password = DataConnectionInfo[2];
            builder.InitialCatalog = DatabaseName;
            builder.IntegratedSecurity = false;
            builder.PersistSecurityInfo = false;

            EntityConnectionStringBuilder entBuilder = new EntityConnectionStringBuilder();
            entBuilder.Provider = "System.Data.SqlClient";
            entBuilder.ProviderConnectionString = builder.ConnectionString;
            entBuilder.Metadata = String.Format("res://{0}/{1}.csdl|res://{0}/{1}.ssdl|res://{0}/{1}.msl", "Proc.BusinessLogic", "DB0." + DatabaseName);
            return entBuilder.ConnectionString;
        }
        public static string getConnectionStringUDL()
        {
            System.Data.SqlClient.SqlConnectionStringBuilder sqlString = new System.Data.SqlClient.SqlConnectionStringBuilder()
            {
                ConnectionString         = objDataLayer.ConnectionString,
                IntegratedSecurity       = true,
                MultipleActiveResultSets = true
            };
            //Build an Entity Framework connection string

            System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder entityString = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder()
            {
                Provider = (objDataLayer.ProviderName == "SqlClient" ? "System.Data.SqlClient" : objDataLayer.ProviderName),
                Metadata = "res://*/GruposEtareosModel.csdl|res://*/GruposEtareosModel.ssdl|res://*/GruposEtareosModel.msl",
                ProviderConnectionString = sqlString.ToString()
            };
            return(entityString.ConnectionString);
        }
Exemplo n.º 30
0
        public SettingPage()
        {
            InitializeComponent();
            string connectionString = ConfigurationManager.ConnectionStrings["VacancysContainer"].ConnectionString;

            if (connectionString.ToLower().StartsWith("metadata="))
            {
                System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder efBuilder = new System.Data.Entity.Core.EntityClient.EntityConnectionStringBuilder(connectionString);
                connectionString = efBuilder.ProviderConnectionString;
            }

            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);

            Server.Text   = builder.DataSource;
            DBName.Text   = builder.InitialCatalog;
            UserPass.Text = builder.Password;
            UserName.Text = builder.UserID;
        }
Exemplo n.º 31
0
        public static string GetConnectString()
        {
            SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
            sqlBuilder.DataSource = "192.168.1.3";
            sqlBuilder.InitialCatalog = "Product";
            sqlBuilder.UserID = "Mondiland";
            sqlBuilder.Password = "******";
            sqlBuilder.MultipleActiveResultSets = true;
            sqlBuilder.ApplicationName = "EntityFramework";

            EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();

            entityBuilder.Provider = "System.Data.SqlClient";
            entityBuilder.ProviderConnectionString = sqlBuilder.ToString();
            entityBuilder.Metadata = "res://*/ProductModule.csdl|res://*/ProductModule.ssdl|res://*/ProductModule.msl";

            return entityBuilder.ToString();
        }
Exemplo n.º 32
0
        private static void test()
        {
            // Specify the provider name, server and database.
            string providerName = "System.Data.SqlClient";
            string serverName = ".";
            string databaseName = "AdventureWorks";

            // 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.IntegratedSecurity = 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.
            entityBuilder.Metadata = @"res://*/AdventureWorksModel.csdl|
                            res://*/AdventureWorksModel.ssdl|
                            res://*/AdventureWorksModel.msl";
            Console.WriteLine(entityBuilder.ToString());

            using (EntityConnection conn =
                new EntityConnection(entityBuilder.ToString()))
            {
                conn.Open();
                Console.WriteLine("Just testing the connection.");
                conn.Close();
            }
        }
Exemplo n.º 33
0
        public SGCoopSTEntities()
            : base("name=SGCoopSTEntities")
        {
            string providerName = "System.Data.SqlClient";
            string serverName = "10.10.11.115";
            string databaseName = "SGCoopST";
            string password="******";
            string userid = "sa";
            // 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.IntegratedSecurity = false;
            sqlBuilder.Password = password;
            sqlBuilder.UserID = userid;

            // 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.
            entityBuilder.Metadata = @"res://*/GOLDMEM.Entity.GMModel.csdl
                                                    |res://*/GOLDMEM.Entity.GMModel.ssdl
                                                    |res://*/GOLDMEM.Entity.GMModel.msl";
            EntityConnection enCon = new EntityConnection(entityBuilder.ToString());
            if (enCon.State== System.Data.ConnectionState.Closed)
            {
                enCon.Open();
            }
        }
        public BennetBasketballDb(string connectionString)
        {
            //  Database.Connection.ConnectionString = ConfigurationManager.ConnectionStrings["BennetYouthBasketballDb"].ConnectionString;
            try
            {

                EntityConnectionStringBuilder enntityConnectionString = new EntityConnectionStringBuilder();
                enntityConnectionString.Provider = "System.Data.SqlClient";
                enntityConnectionString.ProviderConnectionString = connectionString;

                Database.Connection.ConnectionString = enntityConnectionString.ProviderConnectionString;
                Database.SetInitializer<BennetBasketballDb>(null);

            }
            catch(Exception ex)
            {

            }
        }