Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends,

I use the code bellow to connect to my database on my website:

C#
string tempstr = "Data Source=" + "72.55.---.---" + ";Initial Catalog=-------;Integrated Security=False;Persist Security Info=True;User ID=" + "MYUSER" + ";Password=" + "MYPASS";

SqlConnection con = new SqlConnection(tempstr);
con.Open();


Is it secure enough ? or someone who is not professional hacker can capture the username and the password which is sent from his/her computer to my database !?

thanks in advance.
Posted

 
Share this answer
 
Comments
Mohamad77 23-Feb-13 23:19pm    
Thanks a lot.
I've never really worried too much about that because the ConnectionString is in compiled code on my web server. However, if you are really that concerned, write a small program to encrypt your ConnectionString creating a Byte array of the encrypted ConnectionString that you can paste into your web site source code. In your web site source code, decrypt the encrypted ConnectionString before passing it to the SQL Server.

There are examples in the documentation. See TripleDESCryptoServiceProvider Class[^]
 
Share this answer
 
Comments
Mohamad77 23-Feb-13 9:41am    
thanks for the answer.
you mean that I shouldn't connect directly to sql server on my website? I should first connect to my webserver (HOW?!) then the server connect to sql server then answer it ?
Mike Meinz 23-Feb-13 10:41am    
Your web server (web site) runs the code (ASP .NET DLL) that accesses the SQL server (database) to gather and update data. Your user's computer running a web browser connects only to your web server which then accesses the database on the SQL Server. The user's computer running the web browser does not connect to the SQL Server (database).
Mohamad77 23-Feb-13 23:08pm    
yes, right.
But the user computer doesn't run web browser, he run windows application (WinForm) which is written by C# for example.
thanks anyway.
Mike Meinz 24-Feb-13 7:37am    
Your original question said website. Which is correct?

Solution 1 can be used for WinForm app, too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900