locked
Sql server encryption error RRS feed

  • Question

  • I will try to keep it short as possible but here is my problem. We are developing a mobile application and are trying to set up an encrypted sql connection from a windows mobile 6.5 and our server,  I created a certificated and from it created it to our database so that it was listed under the certificate 'folder'.

    We are using 3.5 .net framework,sql server 2005  on server.  and c# as programming language.

    when we tried to to use encrypt=true  TrustServerCertificate=true , we got an error that they are invalid commands( this was also tried on a access connecting to same server using vb but it still was not recognised)

    I also tried to set the server to enforce using encryption  by seting force encryption to yes, what happened was that all normall computer application continue to work normally, but all mobile application could not connect to the sql. the exact error is this

     

    system.data.sqlclient.sqlexception

    class 10

    errors system.data.sqlclient.sqlexception

    line number 0

    number 19

    procedure: "ConnectionOpen (PreLoginHandshake())."

     

    source. .net sqlclient data provider

    stacktrace

    "   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, TdsParserState state)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, TdsParserState state)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()\r\n   at System.Data.SqlClient.TdsParser.Connect(String host, SqlInternalConnection connHandler, Int32 timeout)\r\n   at System.Data.SqlClient.SqlInternalConnection.OpenAndLogin()\r\n   at System.Data.SqlClient.SqlInternalConnection..ctor(SqlConnection connection, Hashtable connectionOptions)\r\n   at System.Data.SqlClient.SqlConnection.Open()\r\n   at DataSync.Login.LoginBTN_Click(Object sender, EventArgs e)\r\n   at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n   at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)\r\n   at System.Windows.Forms.Form.ShowDialog()\r\n   at DataSync.Program.Main()\r\n"

    Saturday, November 5, 2011 1:45 PM

Answers

  • Actually the concept was to access the server from the mobile device through internet by using ssl security, however as you said it is not supported(even though it would be extremely useful), now we are going to use an Api.

    Thanks for your help

    • Marked as answer by Stephanie Lv Tuesday, November 15, 2011 9:44 AM
    Monday, November 7, 2011 1:30 PM

All replies

  • Could you post the full error message? Would also be helpful if you posted the piece of code that fails.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Saturday, November 5, 2011 3:33 PM
  • For the first error when I used encrypt = true it just gave an sqlexception error stating that encrypt is an unknown command

    the code was Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;encrpypt=true;

    (it is not exact code as for security but without encrypt=true it worked always fine)


    as for the other error I already posted the full error

    • Edited by dmintoff90 Sunday, November 6, 2011 8:30 PM
    Sunday, November 6, 2011 8:26 PM
  • I really need to see the full error message which stats that encrypt is an unknown command. I also I want to see the full code which causes this (if you mask username, password etc that OK).

    One I reason I ask for this is that I have never heard of "unknown command" in conjunction with connection strings before.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Sunday, November 6, 2011 10:41 PM
  • This is the coding 

     SQLConnString = @"Server=" + CEReader["SQLServer"].ToString() + ";Database=" + CEReader["SQLDatabase"].ToString() + ";  Uid=" + CEReader["SQLUser"].ToString() + "; pwd=" + CEReader["SQLPassword"].ToString() + ";Encrypt=true";

     SqlConnection SQLConn = new SqlConnection(SQLConnString);

    the exact error is 

    argument exception was unhandled

    Unknown connection option in connection string: encrypt.

     

    When I click view details it gives the following:

     

    system.argumentexception   Unknown connection option in connection string: encrypt.

    message Unknown connection option in connection string: encrypt.

    stacktrace  "   at System.Data.SqlClient.ConStringUtil.ParseStringIntoHashtable(String conString, Hashtable values)\r\n   at System.Data.SqlClient.ConStringUtil.ParseConnectionString(String connectionString)\r\n   at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)\r\n   at System.Data.SqlClient.SqlConnection..ctor(String connectionString)\r\n   at DataSync.Login.LoginBTN_Click(Object sender, EventArgs e)\r\n   at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n   at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterModalDialog(IntPtr hwnModal)\r\n   at System.Windows.Forms.Form.ShowDialog()\r\n   at DataSync.Program.Main()\r\n"

     

    Thanks

    • Edited by dmintoff90 Monday, November 7, 2011 6:48 AM
    Monday, November 7, 2011 6:47 AM
  • Ok  I have more details, I had an api project using visual studio 2010 using .net framework 4 and encrypt = true and trustservercertificate =true worked fine. 

    Don't know if I specified, the project not working is  a smart device application using visual studio 2008 using .net framework 3.5.

     

    I tried copying the connection string from the api project to the smart device ( to make sure that I had not some code missing but it gave same error) 

    From microsoft website  encrypt=true and trustservercertificate are supported even by .net framework 2 so I really don't have an idea on what the problem might be

    Monday, November 7, 2011 8:18 AM
  • Smart Device? SQL Server does not run smart devices, does it? SQL Server Compact Edition runs on smart devices, but despite the similarity in names, it's a completely different engine. I don't know much about SQL Server CE, but since this is a file-based database, and not a server, Encrypt does not really make much sense.


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
    Monday, November 7, 2011 11:38 AM
  • Actually the concept was to access the server from the mobile device through internet by using ssl security, however as you said it is not supported(even though it would be extremely useful), now we are going to use an Api.

    Thanks for your help

    • Marked as answer by Stephanie Lv Tuesday, November 15, 2011 9:44 AM
    Monday, November 7, 2011 1:30 PM