I made a xamarin android app that is supposed to connect to a database. I created a WCF Service that is hosted at a specified address. I then used SLsvcUtil.exe to create a proxy client to call various methods in my service. Previously I had zero issues connecting to the database but after updating my service, it can't even connect to the database. I receive the following error:
System.Reflection.TargetInvocationException: 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.
The machine that is hosting the database has firewall turned off. The WCF Service is hosted on a seperate machine. I checked to see if mssql is accepting remote connections and it is. I have TCP/IP protocols enabled. I don't know if it will help but I am using LINQ to connect to the database and using visual studio. I can see that with using LINQ to SQL, a connection is seen on my machine (which is hosting the database).
Anyone have an idea?
i did some tests about connecting android apps to wcf, and all my tests fails, i recommended to you to change the approach, use REST api or web API to communicate android device to .NET backend.
Related
I am making a Winforms app that must connect to a ASP.NET WebApi web service that I also made. When I connect to the web service from my computer the Winforms app works, but when I install the Winforms app on some computers it fails to connect to the web service with the following exception:
System.IO.IOException: Can not write data to the transport connection:
The interruption of an existing connection has been forced by the
remote host
The problem is that this error might be due to a connection error or due to bugs in either the Winforms app or the web service and I have no idea what might be the cause. I can connect to the server where the web service is hosted. Are there any server logs that I can use to see what might be the cause of this error and if there are, where do I check them?
I am calling a external API from a WCF service and getting below error.
System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it xx.xx.xxx.1:443
If am making same API from console application then it is working fine.
How can I make same API request working from locally hosted WCF service?
When you run the console app you are communicating with the API under a different account to the one that's used when the WCF service hosted in IIS is communicating to the API.
When it's hosted in IIS, it will be using whatever is set in the Identity section of Advanced settings for the application pool. This will usually be something like 'ApplicationPoolIdentity' or 'NetworkService' etc. It may be that this account used for the Identity is unable to communicate to the API.
One test you can do to rule out issues with the account used for the Identity is to use your domain account for the Identity and see if the communication succeeds (i.e. try impersonation).
We have created simple classic Azure VM and have Azure SQL.
We have an application running on VM and trying to do some operation on Azure SQL, however we are not able to access it and got generic 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
We already did list of things:
Added VM's public IP in remote database server
Added Endpoints for 1433 TCP thru Azure Dashboard
Added Inbound rule for 1433 in VM' Firewall
EDIT
For site-to-site VPN,
we linked our database to cloud service of VM
traced IP of database, now we are able to telnet IP with 1433 within
VM.
But still we are logging below error on logger when trying to interact with database.
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.
Are we missing something here
Generally connecting from Azure VM to Azure SQL is a bit different then connecting from outside of Azure.
assuming you are using the latest V12 Azure SQL and latest .Net framework or SSMS
you need to open on your VM outbound connection with TCP port range 11000-11999 and 14000-14999
make sure you do not have any blocker (firewall, 3rd party application that uses this port ranges)
from the Azure SQL end you can just click on "Allow Azure Services" on the Firewall configuration blade to allow connection from within Azure
you can read more about ports used when connecting to Azure SQL here: https://azure.microsoft.com/en-in/documentation/articles/sql-database-develop-direct-route-ports-adonet-v12/
and regards the Firewall configuration on Azure SQL you can read more here: https://azure.microsoft.com/en-in/documentation/articles/sql-database-firewall-configure/#connecting-from-azure
Facepalm moment for us.
Our internet wasn't working that is why we weren't able to connect to our database. As per web we did add MSFT's public DNS Servers i.e. 168.63.129.16 and 168.62.167.9. for classic VM's configure tab.
SqlServerDBConnection.SqlServerDBConnection objDB = new SqlServerDBConnection.SqlServerDBConnection();
string s = SqlServerDBConnection.SqlServerDBConnection.ConnStr;
bool isDBCreated = objDB.CheckAndCreateDatabase(txtSrvName.Text.ToString(), txtUid.Text.ToString(), txtPwd.Text.ToString(), txtDB.Text.ToString());
Above is the code which is being used to connect , create database using script.
Above code runs awesome on local but when I deployed on client side it shows
"Failed to connect to server".
SqlConnection is working fine.
Sql server is connecting database to server.
Is there any code issue or security issue?
I'm not sure there's enough information in the question to resolve the issue but some ideas:
Check if firewall is allowing connections on TCP 1433.
To test it you can simply telnet the server from outside the network to simulate your client's conneciton:
telnet {SERVER_IP} 1433
If you can't connect, check out this document: Configure the Windows Firewall to Allow SQL Server Access
Make sure SQL Server is set to accept remote connections
In SSMS, right click on the server name and select Properties. In Connections section make sure "Allow remote connections to this server" is checked.
Having that said, I wouldn't recommend connecting to database directly from the client site. A better approach would be putting a web API in front of the database and let the API handle database operations. Since the data will be transmitted over HTTP/HTTPS firewall configurations and network access wouldn't be an issue. But it's just a long-term solution obviously.
Hope this helps a bit.
I'm new to Azure and I'm doing a small test:
I have a SQL Azure database and I use EF6.
I also have a cloud service which connects to the Azure database (a "Windows Azure Cloud Service" with 1 web role).
My service has 2 methods:
GetString(): returns a string.
GetUsers(): return users from table [User] in my Azure database (returns IEnumerable<User>)
When I call GetString() it works fine.
when I call GetUsers() I get the following error:
The underlying connection was closed: The connection was closed unexpectedly.
I've also tried using the WCF Test Client and get the same error.
When I create a console app which connects to my SQL Azure (with the same connection string), everything works fine and I get a list of my users from the database.
The problem only happens when connecting to the database from within the Azure service.
My SQL Azure is configured to allow WINDOWS AZURE SERVICES.
Any ideas?
Thanks!
** UPDATE **
When I use the service locally I get the following error while calling GetUsers:
An error occurred while receiving the HTTP response to localhost:50119/MyService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
I figured this out:
Behaviors, Bindings and Services was not configured in my web.config file. I thoughts it should be configured by default and probably i was mistaken.
Thanks!