简体   繁体   中英

ado.net entity framework 4.1 error 40 on database initialization

i'm using ado.net entity framework 4.1 to connect to a sql server 2008 r2 64 bits instance located on my computer. but when i try to initialize the connection i get the following exception:

{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}

the sql service for that instance is running, also sql browser. added exceptions to 1433 port and sql browser. in sql server configuration manager, shared memory is enabled, also named pipes and tcp/ip.

these are my app.config connection string: using a user and password:

 <connectionStrings>
<add name="DbTerminalContext" connectionString="Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;User Id=sa;Password=password;MultipleActiveResultSets=True"
  providerName="System.Data.SqlClient" />

this is using windows identity:

<add name="DbTerminalContext" connectionString="Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;Trusted_Connection=True;MultipleActiveResultSets=True"
  providerName="System.Data.SqlClient" />

i tried using insted of URIEL, .\\SQLIT64, also localhost\\SQLIT64 and i simply cannot connect.

i've searched and tried various solutions found in here and in other places. no solution whatsoever. so can anyone help me? thanks in advance

Check that NamedPipes is enabled in the Sql Server Configuration Manager

(Start -> SQL* -> Configuration -> SQL Server Configuration Manager, then click the SQL Server Network Configuration node).

Try adding metadata resource information to your connection string.

Assuming your Entity Data Model is called "TerminalDataEntities.edmx" there are three files generated in the obj\\Debug\\edmxResourcesToEmbed Folder of your project.

  • TerminalDataEntities.csdl
  • TerminalDataEntities.ssdl
  • TerminalDataEntities.msl

To add these resources to your connection string, you need to change the format of the add-Tags connectionString-Value.

The metadata:

metadata=res://*/TerminalDataEntities.csdl|res://*/TerminalDataEntities.ssdl|res://*/TerminalDataEntities.msl;

The provider:

provider=System.Data.SqlClient;

and the provider connection string:

provider connection string=&quot;Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;Trusted_Connection=True;MultipleActiveResultSets=True&quot;

Put it all together: (With Windows Identity)

<add name="DbTerminalContext" connectionString="metadata=res://*/TerminalDataEntities.csdl|res://*/TerminalDataEntities.ssdl|res://*/TerminalDataEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;Trusted_Connection=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

(Without Windows Identity)

<add name="DbTerminalContext" connectionString="metadata=res://*/TerminalDataEntities.csdl|res://*/TerminalDataEntities.ssdl|res://*/TerminalDataEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=URIEL\SQLIT64;Initial Catalog=IFDB;User Id=sa;Password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Hope this works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM