I put my MVC4 website on our DEV server running IIS7.5 (.NET4.0 ) and it works fine pointing to either server database or my own local db specified as [Machine Name][Sql Instance]. Application is on application pool running under service account. I made sure that user has that service account added to their SQL Logins and given dbo permission.
When I change in connection string to use other user's machine, and specify [machine name][sql instance] it throws an error.
Error says:
[SqlException (0x80131904): 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: SQL Network Interfaces, error: 25 - Connection string is
not valid)]
[EntityException: The underlying provider failed on Open.]
[HttpException (0x80004005): Error executing child request for handler
'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]
This is connection string:
<add name="ProjectUI" connectionString="metadata=res://*/ViewModels.
ProjectUI.csdl|res://*/ViewModels. ProjectUI.ssdl|res://*/ViewModels.
ProjectUI.msl;provider=System.Data.SqlClient;provider connection string="data
source=MYMACHINEID\MSSQLSERVER;initial catalog=DBName;integrated
security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
Things I tried:
I verified remote connections are enabled on the SQL
Enabled TCP/IP port
Added exception to SQL server inbound rules in firewall
Added service account to local database with dbo permissions
The combination of settings that worked:
Enable TCP/IP (and Named Pipes)
Restart the SQL Server service
Ensure service account is added to the database and given appropriate permissions
No firewall settings needed to be changed (no rules were allowed than what was there before)
Connection string modified to: data source=UserMachineID without the server instance (since it was the default one MSSQLSERVER)
Related
I'm working on a tool that uses an SQL Server as a database.
First I was using Visual Studio's localdb, then I was using an Azure SQL Server, both of which worked just fine.
I now tried to host my own SQL Server Express, but I can't seem to connect to it. It's hosted in an Azure VM, I have restarted it, enabled TCP and I have opened Port 1433 in Azure.
I have tried both connecting remotely, running the web-app on my local computer and connecting to tcp:{IP}\InstanceName, as well as running the app on an IIS Server on my VM using .\InstanceName in the connection string (although I still get told to check if the server is set up correctly to handle TCP ? )
Connecting locally on the VM, using Microsoft SQL Server Management Studio works though, so I suspect the connection string in my web.config must be wrong ...
It looks like this:
<connectionStrings>
<add name="defaultConnection"
connectionString="Server=tcp:12.345.678.910\InstanceName,1433;Initial Catalog=master;Persist Security Info=False;User ID=sa;Password={mypassword};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
providerName="System.Data.SqlClient" />
</connectionStrings>
The error message I get is:
Server Error in '/application-name' Application. The remote computer refused the network connection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The remote computer refused the network connection
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: [Win32Exception (0x80004005): The remote computer refused
the network connection]
[SqlException (0x80131904): 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: TCP Provider, error: 0 - The remote computer refused the network connection.)]
(and more but it doesn't seem important - will post if necessary or helpful)
Any idea what I'm doing wrong?
Found the solution on my own:
It's not enough to enable TCP in the Server Configuration Manager, you also have to SQL Server Network Configuration > Protocols for X > TCP > Properties > IP Adresses and set TCP Port to 1433 under IPAll.
SQL Server Express doesn't allow remote connections - by default.
You need to explicitly enable remote connections - easiest way is to use SQL Server Management Studio, connect to it, and then in "Object Explorer" right-click on the server icon, and pick "Properties".
In the dialog that shows up, make sure to tick the "Allow remote connections to this server" checkbox:
I have shared published website and the database files to our client.
they have restored the database to their server.
Now they have changed the connection string in web.config with new server name/IP address and a proper user name and password.
My client said that he can login sql server using the same password and username. But when the website is launched through IIS with same (username and password in web.config and same db structure), it gives an error:
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) (.Net SqlClient Data Provider)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476
Error Number: 53
Severity: 20
State: 0
The ip address of the server starts with 172.
Any help would be highly appreciated.
I would check these things:
I would check the SQL Server Configuration Manager to see if the TCP/IP communication is enabled.
I would check the firewall settings. A firewall could prevent traffic from/to the server.
I would check if another application from the same client can connect to the same server. Then I would check the connection string differences.
If all of the above were playing correctly, then I would check the privileges on the specific SQL Server, on the specific database, for the account I am trying to connect with. Allow everyone to use this database as a first step to check if it is an account-permissions problem.
You could check this connection strings example post.
Hope I helped!
Hi i want to publish my application in a IIS server.
First i create a database in my sql server and put all my needed data on it.
Then i update my web.config to use the new remote Database. Unfortunatly i get an error
ConnectionString:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IntranetDatabase;Data Source=SRVDEV2010\SRVDEV2010" />
Stacktrace :
[SqlException (0x80131904): 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: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
I cheked if i can access database remotly. I create a udlfile to verify my connectionstring, Here is the result.
I don't know why the udl file can connect but not my application. Any help is appreciated
Under which user is the Application Pool configured to run? you're using Windows Authentication which means your IIS App pool should be configured to run under a user that has access to the DB.
i have designed web application in asp.net...i have publish a website..
i have create virtual directory and copy the publish file....
and browse the website...
An error has occurred while establishing a connection to the server. When connecting to >SQL Server 2005, this failure may be caused by the fact that under the default settings >SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 >- Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web >request. Please review the stack trace for more information about the error and where it >originated in the code.
Exception Details: System.Data.SqlClient.SqlException: An error has occurred while >establishing a connection to the server. When connecting to SQL Server 2005, this >failure may be caused by the fact that under the default settings SQL Server does not >allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a >connection to SQL Server)
Source Error:
An unhandled exception was generated during the execution of the current web request. >Information regarding the origin and location of the exception can be identified using >the exception stack trace below.
Your website tries to connect to SQL Server, but the connection string is not matched. You have to change the connection string in your website web.config according to your hosted server.
Open web.config and change the connection string settings.
<connectionStrings>
<add name="DBName" providerName="System.Data.SqlClient" connectionString="uid=; pwd=; database=; server=;Max Pool Size=500"/>
</connectionStrings>
You need to change the connection string and provide uid and password if you are using sql server 2005.One more thing while uploading the published website add the dll from the bin folder
This error might be caused because of several reasons.
1 - Make sure your connection string is correct. You can check here for more info.
2 - Make sure you have "Local and Remote Connections" property is checked with "Using both
Tcp/IP and Named Pipes" option on your SQL Server.
3 - Check your firewall to be sure it does not block requests.
4 - Make sure SQL Server and SQL Server Browser services are started at your computer.
I have domain on the godaddy.com. I have create the database over there.I am able to connect to the database from godaddy.com site with specified user name and password. but when i am going to use same information in my connection string in my asp.net web application on local machine it is showing
"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)"
This error.
my connectionstring is :
<add name="MyConnectionString"
connectionString="Data Source=myDataSource; Initial Catalog=MyDatabaseName; User ID=MyUserId; Password=MyPassword" providerName="System.Data.SqlClient" />
I have provided all required parameters to connection string here.I got this parameter information from godaddy.com database Description section.
You can't do that, their SQL server don't accept external connections.
[EDIT] OK, it seems that my first sentence is incorrect, look here:
http://community.godaddy.com/help/article/4978
http://community.godaddy.com/groups/web-hosting/forum/topic/ms-sql-remote-access/
http://help.godaddy.com/article/4977