Open connection to server not working

Salavat 121 Reputation points
2022-02-27T16:09:58.423+00:00

Hello)
In a UWP app, pulled a button onto the canvas. In the Click handler I wrote the following code (Parl_DB_SP - database name, Table_1 - table name):

private void cl_OpenSQLconnect(object sender, RoutedEventArgs e)
         {
             string connectionString = "Data Source=DESKTOP-D5Q\\SQLEXPSSH;Initial Catalog=Parl_DB_SP;Integrated Security=SSPI;";
             string sqlExp = "INSERT INTO Table_1 (Name,Year) VALUES ('Name',56)";
             SqlConnection sqlConnection = new SqlConnection(connectionString);
             sqlConnection.Open();
             SqlCommand command = new SqlCommand(sqlExp, sqlConnection);
             sqlConnection.Close();
         }

but this code does not work - it shows an error in the sqlConnection.Open( ) line:
System.IO.FileLoadException: 'Could not load file or assembly 'System.Security.Principal.Windows, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'
I'll note right away: TCP / IP is enabled, as is the database service.

What could be the problem?

Universal Windows Platform (UWP)
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,911 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,564 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tom Phillips 17,716 Reputation points
    2022-02-28T15:30:37.203+00:00

    The error you are getting has nothing to do with SQL Server. It is a problem on your machine with your assemblies.

    See:
    https://learn.microsoft.com/en-us/troubleshoot/developer/dotnet/framework/general/manifest-definitions-do-not-match-reference

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Viorel 113.1K Reputation points
    2022-02-27T20:57:30.54+00:00

    If you are using the classes from Microsoft.Data.SqlClient, then try using System.Data.SqlClient, or vice versa.

    2 people found this answer helpful.