Jump to content

System.Data.SqlClient throws a PlatformNotSupportedException


ManselD

Recommended Posts

Ok, so I've got a basic project set up in order for you guys to replicate the issue. Essentially, using System.Data.SqlClient doesn't work only when in a Script. It works fine when in a console application etc...

In this solution, there's three projects. One is DatabaseTest, which is the script which the server loads. Another is ConsoleTest which just calls the same querying code as DatabaseTest, but doesn't have a reference to GTANetworkAPI.

The third is where the querying code is, which is called Shared.

Here's the error I am getting:

qcWmxgm.png

 

Just create a MSSQL DB on your machine called "Test", then you'll be able to test if it connects in the Console app.

Optionally you can add some tables to the DB with this SQL:

CREATE TABLE TEST (
 REEEEEE    INT 
)

CREATE TABLE TEST2 (
 REEEEEE    INT 
)

CREATE TABLE TEST3 (
 REEEEEE    INT 
)

 

Here's the output from the working ConsoleApp with no GTANetworkAPI reference:

CyD9CSj.png

 

And the non-working code inside the script:

8QUYUEU.png

Once it calls Connection.GetTables and reaches the first statement (Which instantiates the SqlConnection class) it dies and claims the platform isn't supported... Considering I'm using the same machine when executing the projects... It gives me a hunch that something is acting weird with GTANetworkAPI.

 

Any ideas?

I've uploaded the project files here:

https://mega.nz/#!dIkkDS4b!43paRU2tMegxU6ZaVTUSFZLZ3tp3YKm2E42CG-rogIk

Link to comment
Share on other sites

46 minutes ago, MiMIMi said:

I believe you have the same problem as previous users. I posted my solution here. 

 

If so were the case I think he should have a file not found exception rather than not supported.

I'm really new to this scripting and don't know the difference between SqlConnection and MySqlConnection, but my query would look something like this.

try
{
      string query = "SELECT [name] FROM [sys].[tables] ORDER BY [name]";
      using(MySqlConnection db = new MySqlConnection(_connStr))
      using(MySqlCommand cmd = new MySqlCommand(query, db))
      {
        db.Open();
        using(MySqlDataReader data = command.ExecuteReader())
        {
          if(data.Read())
          {

          }
        }
      }
}
catch(Exception ex)
{
	Console.WriteLine(ex.ToString()); 
}

 

Edited by introzen
Link to comment
Share on other sites

I've tried copying all the dependencies into the runtime folder previously. I should've mentioned it in the original post.

SqlConnection is for MSSQL databases, whereas MySqlConnection is for MySQL databases.

I'm using Dapper (for returning typed objects), so it can support either. But I would much prefer to work with MSSQL. I'll keep looking into the issue now.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...