web-dev-qa-db-fra.com

Comment activer MultipleActiveResultSets

J'ai la chaîne de connexion suivante dans mon code:

SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["RaiseFantasyLeagueConnectionString"].ConnectionString);

Ma configuration Web pour cela ressemble à ceci:

    <connectionStrings>
<add name="RaiseFantasyLeagueConnectionString" connectionString="Data Source=MATT-PC\SQLEXPRESS;Initial Catalog=Raise;Integrated Security=True" providerName="System.Data.SqlClient"/>

Quelqu'un peut-il me dire où je peux activer MultipleActiveResultSets pour ma connexion?

18
JackofAll

C'est très simple, il suffit d'ajouter 

MultipleActiveResultSets=true;

changez donc, dans votre web.config, la chaîne de connexion de cette manière:

connectionString="Data Source=MATT-PC\SQLEXPRESS;" + 
                 "Initial Catalog=Raise;Integrated Security=True;" + 
                 "MultipleActiveResultSets=true;" 
39
Steve

Essayez ce code

<connectionStrings>
<add name="RaiseFantasyLeagueConnectionString" connectionString="Data Source=MATT-PC\SQLEXPRESS;Initial Catalog=Raise;Integrated Security=True ;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient";/>

Doit renvoyer ceci Article Msdn

4
Ramesh Rajendran
 public static class ConfigurationService
    {
        static public string ConnectionString
        {

            get
            {

                try
                {               
                    // Specify the provider name, server and database.
                    string providerName = "System.Data.SqlClient";
                    string serverName = @"192.168.1.106\SQLEXPRESS";
                    string databaseName = "MyDatabaseName";

                    // Initialize the connection string builder for the
                    // underlying provider.
                    var sqlBuilder = new SqlConnectionStringBuilder();

                    // Set the properties for the data source.
                    sqlBuilder.DataSource = serverName;
                    sqlBuilder.InitialCatalog = databaseName;
                    sqlBuilder.IntegratedSecurity = false;
                    sqlBuilder.UserID = "Bob";
                    sqlBuilder.Password = "Bob1234";
                    sqlBuilder.MultipleActiveResultSets = true;
                    sqlBuilder.ApplicationName = "EntityFramework";

                    // Build the SqlConnection connection string.
                    string providerString = sqlBuilder.ToString();

                    // Initialize the EntityConnectionStringBuilder.
                    var 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.MyDatabaseNameModel.csdl|res://*/Models.MyDatabaseNameModel.ssdl|res://*/Models.MyDatabaseNameModel.msl";

                    var result = entityBuilder.ToString();
                    return result;
                }
                catch (Exception)
                {

                }

                return string.Empty;
            }

        }
    }

Veuillez noter que Models in Models.MyDatabaseNameModel est un nom de dossier de votre projet VS.

0