How to fix "Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net)" - sql-server

I have a web application in visual studio 2017 .NET framework 4.7.1 with identity, that connects to azure sql server database. I am getting an error after submitting login form. The exception message is:
"Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net). Some libraries do not send the server name, in which case the server name must be included as part of the user name (username#servername). In addition, if both formats are used, the server names must match."
The error is only in the web server (azure app service). When I run it locally (localhost) it works fine.
I did what error message suggests but, it did´nt work. I searched about this but, none of the suggestions or solutions I found have worked.
If I remove login stuff, application is able to connect and works so, the problem seems to be the connection string I use to connect to identity tables.
I have tried this connection strings in web.config but none of them have worked:
1.
add name="DefaultConnection" connectionString="Server=tcp:myServer.database.windows.net,1433;Initial Catalog=myDatabase;Persist Security Info=False;User ID=myUser#myServer;Password=myPassword;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False" providerName="System.Data.SqlClient"
2.
add name="DefaultConnection" connectionString="Data Source=myServer.database.windows.net;Initial Catalog=myDatabase;Integrated Security=False;User Id=myUser;Password=myPassword;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"

First, did you set the Allow access to Azrue Service ON?
Please check your Azrue SQL Database firewall settings on portal:
Second, get the correct connection string:
Others, please see: Troubleshooting connectivity issues with Microsoft Azure SQL Database.
Hope this can helps.

Related

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

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

'The network path was not found' every first attempt to Azure SQL Server

I am developing a web application, using Visual Studio 2013 and a SQL SERVER database created on Azure.
Almost every time that I took more than 30 seconds to build and re-run the application (F5) I get this error below. The connection sql connection to SQL Timed-out and this is the error raised.
[Win32Exception (0x80004005): The network path was not found]
I retry the connection and the problem goes away.
The point is that I am loosing so much time on this issue.
INFO ADDED:
I have the SAME issue on SQL Management, first attempt network not found, second attempt it works.
I have seen other computers, running other apps (.net based) on the company with the same behavior on a different SQL Azure server, so, in my mind is something related to azure dns.
I have two SQL connections, to the same server, one for OWIN context, and another used by Entity Framework 6. Both MARS enable.
I don't feel to having the same issue browsing any other website.
My computer is part of an enterprise domain (that I had myself setup, and I am not an expert on Windows Server)
I am using a Macbook with ThunderBolt dongle for ethernet.
My connection strings
<connectionStrings>
<add name="Container" connectionString="metadata=res://*/Models.MakeItMine.csdl|res://*/Models.**********.ssdl|res://*/Models.**********.msl;provider=System.Data.SqlClient;provider connection string="data source=**********.database.windows.net;initial catalog=db**********;persist security info=True;user id=**********;password=**********;MultipleActiveResultSets=True;App=EntityFramework;Connection Timeout=3;ConnectRetryCount=3;ConnectRetryInterval=1"" providerName="System.Data.EntityClient" />
<add name="OWINConnection" connectionString="data source=**********.database.windows.net;initial catalog=db**********;persist security info=True;user id=**********;password=**********;MultipleActiveResultSets=True;App=MakeItMine;Connection Timeout=3;ConnectRetryCount=3;ConnectRetryInterval=1" providerName="System.Data.SqlClient" />
</connectionStrings>
My IP settings
What I tried
Disabled AVG Components
Disabled Windows Firewall for Home/Enterprise
networks
Changed my dns to Google's dns (8.8.8.8/8.8.4.4), if I open
nslookup and try to resolve my database path, it works every time.
Changed my sql connection parameters: "Connection Timeout=3;ConnectRetryCount=3;ConnectRetryInterval=1", so it takes less time to raise the error, and I can retry faster and not loose so much time.
Azure doesn't permit me "pinging" the server, since never returns. So, I am really in trouble on how to troubleshoot/monitor this issue.
Any suggestions on how to troubleshoot this are appreciated.
I did not found the exact problem neither the perfect solution yet, but I do know its a DNS related problem.
So, my fix by now is changing my windows HOSTS file and fixing my database dns to its ip. It's working for now and saving me a lot of debugging time.

Network-related error in SQL Server

the following error appears when I want to launch the Security tab in ASP .NET Configuration site for my ASP NET MVC 4 project:
http://s14.postimg.org/jvizqragv/error_sql.png
I know that there are a lot of questions related to that error, but i tried a lot of the tips for solving this (I tried the suggested solutions here - http://blogs.msdn.com/b/walzenbach/archive/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008.aspx but the error is still here).
But let me explain what are my databases in the solution. I have a local database (an .MDF file in App_Data) and a database for users authentication which was generated by ASP NET MVC. They are all placed in the App_Data folder as I'm trying to work on this solution on different machines. The strange thing is that on my laptop at home there is no such problem - I am able to create roles, explore users and all the functionality in the Security tab and I think there might be some problem with the SQL Server on my desktop machine - I use the Express edition on my laptop and the Developer edition on the other machine where things don't work.
My connection strings are the following:
<add name="FootballTransfers20130717145140Context" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\FootballTransfers.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\DefaultConnection.mdf;Integrated Security=True;MultipleActiveResultSets=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
The first one is for the Entity framework and is related to the database where I store my application specific data. The second one is for the users administration database generated by SQL. Without the second connection string I'm not able to open any action of the Account controller.
It's very strange because it works on one machine and not on another. I was wondering if there's something wrong with the connection string, but I guess there's something with the SQL Server. As I said I tried various solutions but they didn't work.
LocalDB is a feature of SQL Server Express only. You will have to install SQL Server Express on the machine or import your database to your SQL Server and change your connection strings.
In production, you would probably have to move to a full SQL Server edition anyway.
I added the roles i was trying to make in code in the AccountController and now I'm able to register users with roles, but the problem that appeared now is that when I put the Authorize attribute on some action so that only users with certain roles can request them, the following error appears:
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)
When I remove the attribute so anyone can access it, the action works fine. I found some article on the net saying that providers must be specified in the config, but some errors kept appearing that those tags are unknown.

EF Code First - The Provider did not return a ProviderManifestToken string

I'm trying to get a very simply EF Code First example running but ran into the above problem. I've followed the advice here ( How to configure ProviderManifestToken for EF Code First ) but to no avail. I finally managed to get EF to create my database and tables by passing the actual connection string to the DBContext instead of the connection string name I had defined.
Here is how I defined by connection string initially in app.config
<connectionStrings>
<add name="ProductContext"
connectionString="integrated security=SSPI;
data source=MYMACHINE;
persist security info=False;
initial catalog=Product"
providerName="System.Data.SqlClient" />
</connectionStrings>
The name "ProductContext" matches the class ProductContext and the database Product does not exist.
Following the advice on a previous thread I passed the connection string name to ProductContext and the base DBContext cstor. This did not work either.
Finally, I passed the connection string above instead and everything worked, the db was created and the tables.
I'm using SQL Server 2008 and EF 4.1. Any ideas as to what I'm doing wrong?
Thanks,
Ken
Update
The application is a WPF application, not a web application. I get the same exception after I remove the connectionstring from app.config:
"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)"
The problem with answering this question is that the culprit could be more than one issue.
That said, I see a couple things to check:
Your Data Source name looks to be invalid. You need to declare the host name and the instance name. Example: .\SQLEXPRESS (notice the . dot) or MyServerHostName\MySqlInstanceName.
Verify you have a valid data source by using SQL Server Management Studio and trying it there first.
Permissions. You are using integrated security and so the security context of the application making the database connection must have proper rights. Things to check:
Using SQL Server Mgmt Studio, connect to your database. Select your database in the left pane (Object Explorer) --> Databases --> Select your db --> Security --> Users. Make sure you can verify the account being used to run the app has either been granted rights explicitly or can inherit them by being a member of the groups.
When I had this error, my problem proved to be that I had mixed Integrated Security=SSPI with a "Username =" and "Password =" ...not realizing that I needed Integrated Security=false; my user and password parameters were being ignored.
Not sure about this one: I did read some people suggest (at least for troubleshooting) to set Persist Security Info=true.
I had similar problem on EF6 VS 2013, the problem got solved, when I choose 'Save Password' on Entity Framework - Reverse Engineer Code First - Connection Properties Dialog. Hope this helps someone.

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