I recently created a .aspx-website for a school project and it is hosted for free on www.somee.com. Also included in the host's free package is a database (SQLServer).
I don't have SQLServer at home but i need to use the database so I ran a query to create all tables needed. So far everything worked, the database exists (I see this in somee.com's member area) and my website can be visited.
However, I want to Insert/Updata/Delete data from my code behind. I got the following connection-string from my host:
workstation id=sskDatabase.mssql.somee.com;packet size=4096;user id=****;pwd=****;data source=sskDatabase.mssql.somee.com;persist security info=False;initial catalog=sskDatabase
Unfortunately it's not working.
In my web.config:
and my code behind:
connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
string commandString = String.Format("INSERT INTO Mitglied (Position_Id, Username, Passwort, EMail, Beitrittsdatum, aktiv) VALUES ({0},'{1}','{2}','{3}','{4}',{5})", 0, mitglied.Username, mitglied.Password, mitglied.EMail, DateTime.Now, 1);
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandType = System.Data.CommandType.Text;
sqlCommand.CommandText = commandString;
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
sqlCommand.Connection = sqlConnection;
sqlCommand.Connection.Open();
sqlCommand.ExecuteNonQuery();
sqlCommand.Connection.Close();
}
It crashes at sqlCommand.Connection.Open(); with the following error message:
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=119; handshake=14883;
Any ideas why I can't connect to my database?
Contact their support? Normally you should not be able to connect - the database should be hired behind a firewall, likely they changed the default port number at least.
This here is not a replacement for your host's support, you know.
Are you trying it from your school labs? I had the same problem with the same host. In my project it was the school firewall that prevent me from connecting to the database. It's a long shot you can try to connect from your own network (at home or by using your phone as access point) and see if it still happening.
First, you should check if the database server is available, easily you can use a ping command to your ip server adresse.
If the databse server is available you could check if the port of the instance is available, the default is 1433.
To do this you can use telnet command like in this example :
telnet XXX.XX.XX.XX 1433
A important thing that you have to know is that a SQL Server service browser is looking for a client call in the server side, it's this service which receives the call and able the communication. You have to make sure that this service is working too.
Related
While trying to connect to SQLAnywhere (Sybase) database (C# code) from Azure ServiceFabric:
await using var connection = new SAConnection(connectionString);
await connection.OpenAsync();
receive iAnywhere.Data.SQLAnywhere.SAException
Connection error: Connection was dropped (may not be a SQL Anywhere server)
Error code is Error 832. This is generic connection error: An error occurred while attempting to establish a connection with the database server, but before attempting to connect to a database. Failure to initialize a communication link during the connection attempt is an example of this error. Creating a debug log file using the LogFile connection parameter may provide more information.
Locally it works, but does not work from Service Fabric.
Fix ideas tried:
Missing driver? Looks like no, Sybase (now SAP) SQLAnywhere requires special driver or client - but locally also works without this driver, just with iAnywhere.Data.SQLAnywhere.NETCore nupackage installed
Network connection/ firewall problems? Looks like no, database server can be pinged from Service Fabric node
It was another traffic protection tool. Although it was possible to telnet the port, still traffic from app was blocked by another tool.
Had a similar issue - turned out that whilst standard incoming traffic from the Sybase Server had been whitelisted in our Firewall, encrypted traffic from this had not been.
This meant I could ping and connect with Telnet, but got the same error when trying to log-in with my credentials
Connection error: Connection was dropped (may not be a SQL Anywhere server)
Our comms team solved the issue by whitelisted encrypted traffic from the server address as well. They also mentioned it possibly could have been solved we shared a valid security certificate for the encrypted data with their team, but were happy with the first course of action.
I am attempting to connect to a presto coordinator that resides on an EMR cluster. I am using the Terradata ODBC driver. I have both tested the driver by putting the pertinent details into the DSN via ODBC connections dialog and written a simple C# application that creates a connection (see the code below).
The problem is that I am getting a 404 error returned when the connection is either tested in the DSN dialog or opened in the C# code.
I believe the security group settings in AWS are fine as I am definitely getting through to the master node which is configured to have port 8080 open.
var connectionString = "Driver=Teradata Presto ODBC Driver;Host=xxx;Port=8080";
OdbcConnection cn = new OdbcConnection(connectionString);
OdbcCommand cmd = new OdbcCommand(sql, cn);
cn.Open();
This code when run will throw an exception with "ERROR [HY000] [Teradata][Presto] (1040) Error with HTTP request, response code: 404" as a message.
Am banging my head against the wall with this one. Any insights are very much appreciated.
The problem was the port I was connecting to Presto on. I had got it in my head that it was 8080 but in fact it was 8889.
I've written a tool that validates emails, mostly copied from various examples on the subject around on the internet (user Don Worthley compiled a decent collection of code samples here https://delicious.com/dworthley/email.validation). Unfortunately after creating the socket and the IPEndPoint from the email to verify's hostname IP and port, my code always fails to connect to the socket due to timeout.
Here is the pertinent code (fails at s.Connect(endPt) due to timeout):
private bool smtpCheckEmail(string email)
{
try
{
string[] host = (email.Split('#'));
string hostname = host[1];
IPHostEntry IPhst = Dns.GetHostEntry(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
using (Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
try
{
s.Connect(endPt);
}
catch
{
s.Close();
return false;
}
From my research others have reported success with similar code so it might be an issue with my server host. The MVC project is on a GoDaddy VPS with Windows 7 and standard firewall/MSSE as protection (I've tested with both disabled with same timeout result).
I've verified I can telnet to my own host and run through the various HELO, Mail from etc commands but it also times out if I try to connect to smtp for other hosts.
Maybe it's an ISP issue?
I've also tried installing EmailVerify for .NET trial but run into the same problem where any validation at or above SMTP check times out.
Would be great to get some suggestions of what might be the problem and how to troubleshoot it.
Edit: After doing some comparison testing with one of my Azure VPS it looks like it is likely to be server related, "telnet 74.125.206.108 smtp" (gmail's smtp host IP) through command line connects on the Azure box but not on the GoDaddy one my project is on.
I also notice that when my code pulls the IP from the host name (Dns.GetHostEntry(hostname)), in this gmail example it returns 216.58.216.37 which matches what I get if a run nslookup in cmd for gmail.com, however the IP for smtp that I can telnet to is for gmail is 74.125.206.108 which matches the nslookup record for smtp.gmail.com. Could my code be grabbing the wrong IP addresses in many cases here?
Turned out to be a limitation of GoDaddy VPS. Transferred code to an Azure hosted project and it worked great.
I want to connect asp.net application hosted at a web server with sql server 2012 db hosted at another remote location.
I have enabled the TCP/IP on sql server, also set port 6322 for ip1 and ipall.
but if i go to my web server and telnet into the db server, no connection is established.
in ASP.net page just to test the connection i am using the connection string as below
<add name="DBConnectionStringTEST"
connectionString="Data Source=<db ip address>; Initial Catalog=<db name>; Persist Security Info=True;User ID=<username>;Password=<password>;connection timeout=0;Max Pool Size = 100;Pooling = True"
providerName="System.Data.SqlClient" />
my questions,
1) is there something i am missing, like wrong port.
2) do i need to give db ip address(client_net_address) or the actual db server address.
3) do i need to ask the server administrator to allow web server ip address to connect.
4) what is the quickest way to test if the web server can talk to the sql server without having to amend the connection string in asp.net application every time i make changes.
NOTE: i have searched other similar topic but couldnt find any answer which worked for me.
Without an explicit port or instance name specification, the default 1433 port will be used. Specify your custom port in the connections string:
<add name="DBConnectionStringTEST"
connectionString="Data Source=<db server ip address or host name>,6322; Initial Catalog=<db name>; Persist Security Info=True;User ID=<username>;Password=<password>;connection timeout=0;Max Pool Size = 100;Pooling = True"
providerName="System.Data.SqlClient" />
An easy way to test network connectivity is with TELNET:
TELNET <db server ip address or host name> 6322
This will show an empty console window if successful. Press ctrl-C to close.
You can also verify port connectivity with the Powershell command below if you don't have TELNET installed:
6322 | % { echo ((new-object Net.Sockets.TcpClient).Connect("<db server ip address or host name>",$_)) "server listening on TCP port $_" }
1) is there something i am missing, like wrong port.
From your posted connection string it looks like you are using default instance. if it's indeed named instance then provide the same info in your connection string.
2) do i need to give db ip address(client_net_address) or the actual
db server address.
It should be actual DB server IP address/Hostname along with Db server installed instance name.
3) do i need to ask the server administrator to allow web server ip
address to connect.
If you are providing correct IP addr/hostname/port/credential then it should allow you to connect through. (provided your DB admin have already created DB user for you)
4) what is the quickest way to test if the web server can talk to the
sql server without having to amend the connection string in asp.net
application every time i make changes.
By creating a UDL file. Open a notepad and save it as test.udl. Once saved -> double click the file -> provide all info and test the connection. It should look like below
EDIT:
To configure a universal data link (.udl) file
Double click on he file named test.udl
On Provider tab select SQL Server Native client 10.0
On Connection tab
enter BRR=SQL-N1 as Server Name
In Username and password section provide SA and password
Click on Test Connection
See Here for more information on this.
I was looking in posts similar to mine, but didn't find any response to my issue.
Recently the MySql server was changed, right now I'm using a different one,
I use this connection string in my asp.net vb web application project:
<add key="MySQLConnStr" value="server=xx.xxx.x.xx; user id=mysql_link; database=mysql; pooling=false; password=xxxx"/>
Ok when I run the WebApp in my computer (development environment) it works perfect, now, in the host (production env.) I get the "Unable to connect..." error.
What could be the problem here??? I just changed the old MySql server ip for the new one.
I restarted the application pools in the host, restarted the webapp as well, but nothing.
thanks in advance!
Is it possible that your MySql runs on different port number?.
(any port different from the default 3306)
If so, add to your connection string "Port=xxxx;"
EDIT: It's also possible that your MySql Administrator has not given to the ip address/name of your server the permission to connect whilst has given them to your local pc
complete connection string in c# code ..
public MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=XXXX;database=yourDBname;Port=XXXX");
Thanks