简体   繁体   中英

Cannot connect to database (free host somee.com)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM