public static string GetConnectionString(ProfileMaster profile) { //return string.Format("data source={0};initial catalog={1};user id={2};password={3} multipleactiveresultsets=True;App=EntityFramework", profile.DatabaseIP, profile.DatabaseName, profile.UserName, profile.Password); string providerName = "System.Data.SqlClient"; string serverName = profile.DatabaseIP; string databaseName = profile.DatabaseName; // 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://*/Models.MoviesDB.csdl| res://*/Models.MoviesDB.ssdl| res://*/Models.MoviesDB.msl"; return entityBuilder.ToString(); }
Saturday, February 22, 2014
set entity framework connection string programmatically
Share This!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment