SQL Server 2008 connectionString question

I am trying to connect to my SQL Server 2008 database using ASP.NET MVC 3. Here is my connection string:

<connectionStrings> <add name="AppConnectionString" connectionString="Data Source=(local);Initial Catalog=DatabaseName;User Id=UserName;Password=PassWord;" providerName="System.Data.SqlClient" /> </connectionStrings> 

Any idea on what's wrong?

When I try to execute a query in my DbContext, I get this exception:

  • $ exception {"The provider did not return the ProviderManifestToken string." } System.Exception {System.Data.ProviderIncompatibleException}

  • InnerException {"A network-related or specific instance error occurred while establishing a connection to SQL Server. The server could not be found or is unavailable. Verify that the instance name is correct and that SQL Server is configured (provider: SQL Network Interfaces, error: 26 - Location error server / instance) "} System.Exception {System.Data.SqlClient.SqlException}

Can anyone help me?

thanks

+6
asp.net-mvc-3 connection-string sql-server-2008-r2
source share
7 answers

First check if your mssqlserver services are running. Just run net start mssqlserver at a command prompt.

Then try changing the connection string Data Source=(local) to Data Source=.

All of the above assumes that you have a sql server installed on your local machine.

+3
source share

This error means that either the name of your data source in your connection string is incorrect, or your sql server is not configured to allow remote connections: see here how to fix it.

+3
source share

Can you ping a server?

You can create a new empty text file, rename it to test.udl, double-click on it and create your own connection string in this way. (A dialog box opens in which you can select the provider, server, database, etc.).

also see w ww.connectionstrings.com for example connection strings

An example is also taken into account. for example, if you use sqlexpress, it may be (local) \ SQLEXPRESS

+2
source share

In addition, (local) attempt (localhost) or 127.0.0.1 (feedback address - and there is no place like ;-)

Also one period will be "." allow local machine.

The connection string and the advice above suggest that you are trying to connect to an unnamed instance by default. If your server instance is specified, you need to include it as part of your conn string, for example:. \ ServerName

More information can be found at: http://connectionstrings.com

+2
source share

I had a similar problem and these were the steps that helped me:

1) Your application should have App.config containing a connection string with a name with the same name as your class inherited from DbContext. In my case, "TestEF_CF.ProductContext".

 <add name="TestEF_CF.ProductContext" connectionString="Data Source=localhost;Initial Catalog=ef_cf_test;Integrated Security=True" providerName="System.Data.SqlClient" /> 

2) The database cannot be created before you start using it. Just set the start directory to the name you want to create the Entity Framework when it automatically creates the database.

See my stackoverflow question for more info if you need it: Entity Framework 4.1. The first code freeze

+1
source share

If you look at InnerException, it is possible that you really have a problem with Login.

What I needed to do to fix this, change the account that DefaultAppPool runs as NetworkService (go to "Advanced Settings" and change "Process Model", "Identification"), and then select the account that has access to your database.

Assuming your application is running in IIS using DefaultAppPool.

I did this NetworkService and granted NT AUTHORITY \ NETWORK SERVICE user access to my existing database.

This allowed me to connect. My case may be specific, but I thought I would share it just in case.

+1
source share
  SqlConnection [object name]; [object name] = new SqlConnection("Data Source=Server_address/name;Initial Catalog=myDatabase;Integrated Security=True"); [object name].Open(); 

Note. The square brackets that are shown should not be placed, only the name of the object must be placed. Server_address: the name of your computer. myDatabase: the name of your database.

0
source share

All Articles