Entity Web Configuration File

This code works fine:

<connectionStrings> <add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=myDB;Integrated Security=SSPI; " providerName="System.Data.SqlClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"> <parameters> <parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" /> </parameters> </defaultConnectionFactory> </entityFramework> 

but this code does not work:

 <connectionStrings> <add name="EFDbContext" connectionString="Data Source=.\MSSQLSERVER2008; Initial Catalog=myDb;Integrated Security=SSPI;User ID=useradmin; Password=pass; " providerName="System.Data.SqlClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"> <parameters> <parameter value="Data Source=.\MSSQLSERVER2008; Integrated Security=True; MultipleActiveResultSets=True" /> </parameters> </defaultConnectionFactory> </entityFramework> 

The second code must be running on a remote server with an instance of MSQSERVER2008, and when the page loads, the following message appears:

An error occurred while retrieving vendor information from the database. This may be caused by the Entity Framework using the wrong connection string. Check the internal exceptions and verify that the connection string is correct.

+8
asp.net-mvc entity-framework
source share
3 answers

The problem is the Integrated Security parameter. If it is set to True, .Net try to open a connection to the current user event, if you specify a user and password. Therefore, to open a connection with a specific user, set Integrated Security to False, and it will work.

 <connectionStrings> <add name="EFDbContext" connectionString="Data Source=.\MSSQLSERVER2008; Initial Catalog=myDb;Integrated Security=SSPI;User ID=useradmin; Password=pass; " providerName="System.Data.SqlClient" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"> <parameters> <parameter value="Data Source=.\MSSQLSERVER2008; Integrated Security=False; MultipleActiveResultSets=True" /> </parameters> </defaultConnectionFactory> </entityFramework> 
+11
source share

Here is what I need to do to bind EF using the dynamic parameters of the connection string, although my settings are entered by the user and not the web configuration:

  // Set the properties for the data source. sqlBuilder.ConnectionString = "Integrated Security=SSPI;"; sqlBuilder.DataSource = serverName; sqlBuilder.InitialCatalog = databaseName; sqlBuilder.ConnectTimeout = 60; sqlBuilder.MultipleActiveResultSets = true; if(!string.IsNullOrEmpty(userName) || !string.IsNullOrEmpty(password)) { sqlBuilder.UserID = userName; sqlBuilder.Password = password; //sqlBuilder.IntegratedSecurity = false; } else { sqlBuilder.IntegratedSecurity = true; } 
+1
source share

make sure your code line is correct:

 "Data Source=.\MSSQLSERVER2008; Initial Catalog=myDb;Integrated Security=SSPI;User ID=useradmin; Password=pass;" 

check your sql server.

0
source share

All Articles