Exception when using System.Data.SqlClient

I’m running an SQL Database over a network and am having issues with connecting and injecting data into the tables.

I’ve installed the toradex sql compact v 3.5 on my colibri, and included the reference for System.Data.SqlClient

I get the exception

File or assembly name 'System.Data.SqlClient, Version=3.0.3600.0, Culture=neutral, PublicKeyToken=3BE235DF1C8D2AD3', or one of its dependencies, was not found.

Here’s the code I’m executing in my c#. I know the code itself works for injecting data because I tested it in a standard visual studio on my PC.

string connString = "Data Source=192.168.1.213,1433;Initial Catalog=TestDB;Trusted_Connection=True;";
string cmdText = String.Format("insert into dbo.TestDBEvents(ID, Name) values (0,'{0}');",DateTime.Now);
using (SqlConnection conn = new SqlConnection(connString))
{
    conn.Open();
    SqlCommand cmd = new SqlCommand(cmdText, conn);
    SqlDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
        System.Diagnostics.Debug.WriteLine(string.Format("{0}, {1}", reader[0], reader[1]));
    }
    reader.Close();
}

You need to install SQL client on your device:
https://docs.toradex.com/102041-toradex-sql-compact-v-3-5.zip

I’ve installed that. I can see the DLL files in my FlashDisk/System folder, and I’ve also copied over the DBNETLIB.DLL from my PC. I did notice that when I compile and send to the device, it deploys sql.wce5.armv4i.CAB and sql.dev.enu.wce5.armv4i.CAB. I’ve tried pulling these from my PC and installing them manually and get an Unsupported System Version error claiming the program is not compatible with the current operating system.

Any other suggestions?

Do you have System.Data.*.dll in your \FlashDisk\System folder, can you check if the version matches the one expected by your app (the one in the error message)?

Thank you Valter!
I didn’t have the system.data.sqlclient.dll in my \FlashDisk\System folder, however I did pull it from my PC and add it as an included reference for my program. Well for whatever reason, it wasn’t copying the file to where my .exe exists… Once I copied it over it at least stopped crashing immediately where it was…

Now I just need to get to the bottom of why it’s giving my SQLExceptions.

Thanks again!

Thank you Valter!
I didn’t have the system.data.sqlclient.dll in my \FlashDisk\System folder, however I did pull it from my PC and add it as an included reference for my program. Well for whatever reason, it wasn’t copying the file to where my .exe exists… Once I copied it over it at least stopped crashing immediately where it was…

Now I just need to get to the bottom of why it’s giving my SQLExceptions.

Thanks again!

Non an expert on SQL, but you are trying to read data back from an insert command that usually returns no data.