Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote SQL

Status
Not open for further replies.

gplusplus

Programmer
Jan 17, 2007
30
US
Basically all i want to do it connect remotely to a SQL server on my
personal webpage that is hosted by bluehost.com

I have added a sql db on the site with a user name and password. I have also
added my IP to the white list and access host list for sql in cpanel.

Then I wrote a very small app just to test to see if i could simply connect
to it.

Basically i have a form with a button and a click event for the button. the click event calls a sql() function.

I wrote the application in c#... here is my connect function inside my sql() function:

Code:
private void sql()
{

SqlConnection myConnection = new SqlConnection("user id=my_user_id;" + "password=my_pwd;server=my_url" +
"Trusted_Connection=yes;" +
"database=my_db; " +
"connection timeout=30");
try
{
myConnection.Open();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
Console.WriteLine(e.Message);
}

}

Its not allowing me to connect at all. I get this error from my exception:

"An error has occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact that
under the default settings SQL Server does not allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to
SQL Server)"

I am using VS 2005 Professional.

I opened port UDP 1434 on my linksys router.
I disabled the windows firewall and norton.

I added the ability to have Remote connections via TCP/IP in Microsoft SQL Server 2005 Configuration Manager.

I also called bluehost and tech support said i have configured everything
properly on that side and he was able to connect to it.

Is there anything that you might be able to suggest to help me get this
connection.

I would very much appreciate your time and consideration with this problem.

Thanks so much,
 
Are my_user_id and my_password variables or did you just place them in there? Assuming that's just what you put there.

You also have the wrong connection string for a SQL Connection. Try this:

Code:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

More here:
Hope this helps,

Alex

[small]----signature below----[/small]
I can't compete with you physically, and you're no match for my brains.
You're that smart?
Let me put it this way. Have you ever heard of Plato, Aristotle, Socrates?
Yes.
Morons!
 
as it stands now there are too many variables to say what the problem is exactly. network, firewall, cnn string, db configs, app configs...

are you using sql server 2k or 2k5? if 2k5 install sql server express on your local box and connect/test with that. once that connection is working then try to migrate to the remote box.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I tried your connection string but i get the same error.
Any other ideas of what i am doing wrong ?

BTW:

my_user_id and my_pwd are just place holders so i dont give my login away for free ;)

Thanks again!
 
I am using SQL 2k5 and im trying to connect to my sql db on my site that is hosted by bluehost.com.... I have verifired my sql settings on the server with the bluehost tech support and they are all set correctly.
 
right, but before you cross the net to connect to a db try connecting to a local copy. this eliminates security and hardware settings between you and server.

if the connection fails the problem is your code. if you can connect the problem is most likely and security/auth setting between your box and the server.

some hosting companies only allow certain servers to connect to one another. example: only the web server can connect to the db server (all other connections are denied). this would prevent you from connecting to the db server from your local box.

create a simple "hello world" webpage which opens/closes a connection to the database. upload the web server and view the page.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top