Issue with website deployed to IIS and connecting to SQL Server 2012, getting network not found error - sql-server

I have deployed a website to IIS and it is trying to access the database via the connection string.
My SQL Server and connection string is correct as I have tested it in the following ways:
My development environment streams data correctly
Connection to SQL Server is good as I could see from SQL Server Management Studio
Other pages of the website that are deployed are correct and only those pages that stream data is failing.
The problem is that it is only through the IIS website we have this error and when I run it from Visual Studio it is all right.
Here is the stack code I get:
Stack trace error
My connection string:
<add name="cnnSQLDB"
connectionString="server=**********;database=*********;Integrated Security=True;User ID=******;Password=******;"
providerName="System.Data.SqlClient"/>

Make sure that port 1433 is open on your firewall. That is the port SQL Server uses.

I was able to solve this issue based on hints provided here. I had to do the following changes:
Update the SQL connection string and set "Integrated security=false". In that way it will use the login credentials provided in the SQL connection string.
Create a new user as provided in the SQL connection string and GRANT the necessary accesses.
When I copied the databases from the production environment to a new environment the GRANT permissions for the user mentioned in the connection string was not updated.
But by checking the port status via the command 'sp_readerrorlog' gave me clues and led me to a solution. Some other links that helped me were: this and this

Related

Throwing this error message "Error -1 - SQL connection failed." when trying to connect SQL server from Microsoft Azure's Database Migration Services

We tried to do one poc which meets our upcoming requirement in my personal Laptop. The requirement is migrating the on premise sql database into azure sql database.
The screen shot of error is,
Connection error message and description
Below are steps which we have done.
Step1:
We have created a sql database in azure portal. The server name is like sundar64599.database.windows.net
The Screenshot is here, Sql database in azure poral
Stpe2:
Then We have done the assessments and created the migration project in Data Migration Assistant tool and we deployed it successfully.
Step 3:
Then we created a Database Migration Services and tried to create a migration project.
Here we entered the source server details to connect and it throws the error as mentioned added the screenshot above.
And also we tried the below to resolve this connect issue.
1. In sql server confuguration management,
a. We restarted the sql server and tried to connect. But it fails. The screenshot is Sql server restart
b. Then we had set the TCP port as 1433 and dynamic port as 50313 and tried to connect. But it fails. The Screenshot is, Tcp with dynamic port
c. Then we had set the TCP port as 1433 and dynamic port as empty and tried to connect. But it fails. The screenshot is, Tcp empty dynamic port
2. In Sql database of azure portal, we checked the client ip and added the exact ip and tried. Even it fails. The Screenshot is, Firewall ip settings
Please add your suggestions to resolve this connection issue.
Thanks in advance,
Samidurai Tamilmani
You need to provide the FQDN (Fully Qualified Domain Name) or Public IP of the source server as described here. The way you are providing the source server will work in the local network but not from outside, which is required by the Azure Migration services.
So make sure that your source server is available from the internet. You can have a look at the complete steps here - https://learn.microsoft.com/en-us/azure/dms/tutorial-sql-server-to-azure-sql

IIS Connection IIS Basic User Settings Specific User Cannot Connect to SQL Server using Perl DBI

My Perl IIS web application is getting an SSL Error when the Perl DBI tries to connect to my MS SQL Server database version 11.0.7001 (that's what is listed in SQL Server Manager). The Perl application runs under IIS, and my IIS Basic User Settings Connection is set to Specific User (Domain Administrator).
The SQL Sever database resides on the same system as IIS. The distribution of Perl is Strawberry Perl; IIS' version is 8.5.9600.16384.
I can connect to the database using the SQL Server Manager locally on the server as well as remotely from my workstation. The connection type is SQL username and password. The IIS application listens on port 8085. The IIS permissions are not restricted, and there is no SQL server connection string as part of IIS.
The first page of the application loads, but this first page does not try to connect to the SQL Server database.
I have been looking at Stackoverflow posts -- like this one -- for a while, and have tried some of the suggestions like making a system DSN (which tests correctly), instead of a DSN string in Perl.
None of the suggestions have helped, and many but not all of the posts are dealing with security and certificates, not an application that is behind a firewall. In other words, I do not have security turned on.
To the best of my knowledge there is no security turned on for this application, and Named Pipes and TCP/IP were already turned on, as was suggested in one of the posts I read.
Here is the error:
[Microsoft][ODBC SQL Server Driver][DBMSLPCN]ConnectionOpen (SECCreateCredentials()). (SQL-01000) at ../../include/DbArgs.pm line 266.
DBI connect('driver={SQL Server};server=arlsql\arlsql;database=BuildingPermit;uid=user;pwd=pwd','',...) failed: [Microsoft][ODBC SQL Server Driver][DBMSLPCN]SSL Security error (SQL-08001) [state was 08001 now 01000]
Any suggestions on what to try next would be appreciated.
Edit 1/6/2020
I need to add that my C# client application using .Net ODBC objects successfully accesses the same database on which the web-based Perl DBI code fails. The username and password are the same for the client application as that used in the Perl CGI.
The IIS user for this application runs as the domain administrator, but when creating the DBI connection uses the same username and password. The database is set up for SQL username and password, and, as stated previously, there is no security set, at least that I can tell.
This does not answer the question but is instead a workaround. I consider the following a workaround, because I would still like to know why the DBI call failed with a specific user.
I switched my IIS Basic User Settings Connection from Specific User (Domain Administrator) to Application User (pass-through authentication).
After making this change and restarting IIS, the Perl DBI connection worked, but why?

Error while trying to connect to SQL Server - localhost

I have checked the instance name, auto close is set to true, allow remote connections on the server is checked. The server is running when I open the SQL Server configuration manager. I have even rebooted. I have created this db the same way as all others. I use Entity Framework and have checked the names in the web.config and they match. This is the default connection string from the wizard - I use for testing before I deploy. I just can't think of anything else to check to figure out why it won't connect. Working inside SQL Server everything is fine.
Here is the general 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: Shared >Memory Provider, error: 40 - Could not open a connection to SQL Server)
Config:
connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string='data source=.\SQL_1;attachdbfilename="C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQL_1\MSSQL\DATA\A_db.mdf";integrated security=True;connect timeout=10;user instance=True;multipleactiveresultsets=True;App=EntityFramework'" providerName="System.Data.EntityClient" />
Thanks in advance.
Let me preface this answer by saying that proper setup of a SQL instance is not as easy as Microsoft would like you to think with the entity framework. It's a little bit involved and requires that you put your DBA hat on for a little bit.
The error you have indicates that the web instance is attempting to connect to the SQL server using Windows Integrated Security. This will work fine if (a) the windows user that the process is running as (which can be configured in IIS) is authorized to log on to the SQL server and has a valid login in the database and (b) if the SQL server is on the same machine or in the same domain as the IIS server.
In light of this, I recommend using SQL Server authentication. If you need to know how to do this, I recommend searching for "SQL Server Authentication setup" - here is an article that I found which might help you set this up.
http://msdn.microsoft.com/en-us/library/aa337562.aspx
In general, I recommend taking the following actions:
Connect to the sql server using MS SQL Management Studio.
Permanently attach your database, then use the Initial Catalog property on your connection string rather than AttachDbFileName
Then set up your login username and password on the SQL server, and create a login in the database for it.
Make sure your login can only execute the stored procedures you want it to execute. Deny it access to running sql statements.
You will also need to add the username and password to your connection string, and set IntegratedSecurity=false.
Let us know how things go once you get your SQL server set up properly.
This error means that your provider code cannot find the SQL Server. If you have checked the server instance name (it should be <yourLocalServer>\SQL_1), then it could be the attachdbfilename= parameter, as this is a really unreliable way to specify the database to connect to (you should be using the Database Name, not the file name), because there are about a hundred reasons that the file name could change that have nothing to do with your application.

ASP.NET MVC2.0 remote SQL server - Login failed for user '<username>'. Reason: Not associated with a trusted SQL Server connection

first I have checked that Server Authentication is already set to:
"SQL server and Windows Authentication mode" (mixed mode)
้here 's my web.config connectionstring
<connectionStrings>
<add name="StockConnectionString" connectionString="Data Source=192.168.0.2;Initial Catalog=Stock;Persist Security Info=True;User ID=op;Password=operator" providerName="System.Data.SqlClient"/>
</connectionStrings>
Whene I test running (ctrl+F5) under VS2010 development this can connect to remote SQL server without any problem. but when i publish this project to local IIS (same web.config) an error occured..
Login failed for user 'op'. Reason:
Not associated with a trusted SQL
Server connection.
also i can connect to SQL server via SQL server Management Studio with SQL server authentication same user/pass.
no idea what's wrong with this.
finally, after 3 days can't figure this out. then i tried start over.
created a new project (ASP.NET MVC 2 web app) in VS2010.
go to Database Explorer > Add Connection..
use SQL server authentication to remote SQLserver directly instead of local.
then gotcha!! it told me..
this server version is not supported. you must have Microsoft SQL server 2005 or later.
my project was created under Win XP connect to SQLserver 2000 and it's work fine. now the answer for an error above is..
Visual Studio 2010 dropped support for SQL Server 2000. You'll either have to go back to VS2008/SL3, upgrade your SQL Server, or do things manually outside of Visual Studio.
...really appreciate this so much
Does it make any difference if you add this to the connection string ?
Trusted_Connection=False;
A clue is that it's saying that it's not trusted which indicates it's not using the username and password from the string. Has a connection string been possibly imported into IIS ?
Trusted is windows authentication which by the error is being used. Sql server authentication is username and password which you are trying to use.

IIS 7 can't connect to SQLServer 2008

Sorry if this is the most seen question on the web, but this is my turn. I am trying to publish my asp.net mvc app on IIS 7 under MS Sql Server 2008. I am on a Windows Server 2008 virtual machine. I get the following classical 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: SQL Network
Interfaces, error: 26 - Error Locating
Server/Instance Specified)
Under SQLServer, Allow remote connections is checked. My connection string is:
Data Source=.\MSSQLSERVER;Initial Catalog=mydbname;User Id=sa;Password=mypassword
I also tried with no username/password and "Integrated Security=true". There is only one instance of SQLServer installed.
I tried to access my web page locally and remotely. There is no active firewall on the virtual machine.
Make sure you have TCP/IP set up as a transport in your SQL Server configuration tool.
Thanks guys for the try. I found the solution and it is related to an info that I forgot to give. I hope it can help someone as new as me on these things.
I use NHibernate, and the connection string is actually in the nhibernate.cfg.xml file. The one in the web.config file is actually used by my various providers (users/roles). I fixed that by removing the connection string from the NH config file. I now retrieve it with:
string connectionString = ConfigurationManager.
ConnectionStrings["myConnectString"].ConnectionString;
and I set it in NH with:
Configuration cfg = new Configuration();
cfg.Configure(cfgFile);
cfg.SetProperty(NHibernate.Cfg.Environment.ConnectionString, connectionString);
Now I get:
Cannot open database "mydb"
requested by the login. The login
failed. Login failed for user 'NT
AUTHORITY\NETWORK SERVICE'.
But this is another story, for another question if I can't find the answer.
PS: I had to use "." as the server name otherwise .\MSSQLSERVER was producing a new error "invalid connection string". Thx Ian and Jared for the tip.
is that the actual data source line from the web config?
If so then it's should be in quotes of course, for safety add a ; on the end and check that is the actual name of your instance, you can check windows services for your instance name.
try substituting localhost instead of . and can you connect from sql server management studio using the credentials in your connection string?
As mentioned by Robert, try:
ConnectionString="Data Source=(LOCAL)\MSSQLSERVER;Initial Catalog=mydbname;User ID=sa;Password=mypassword"
I'm not sure if connection strings are case sensitve, but I notice that you have 'Id' instead of 'ID'.
Edit:
Am not sure if you need \MSSQLSERVER?
are you sure it's a named instance of SQL?
try
Data Source=.;Initial Catalog=mydbname;User Id=sa;Password=mypassword
UPDATE:
from this site
did you try the following:
Make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true).
Make sure SQL Browser service is running on the server.
If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.
Well I am facing the same above issue since morning (past 8 hours) did lots of stuff like create a Domain Name, setup a new application pool identity but nothing worked :(
I just made a small changes in web.config file for connection string that is:
Integrated Security=False instead of True... and now it is working perfectly

Resources