Wenn ich jedoch die Datenbank abfrage, löst das Programm (das ausgeführt wird) eine ungültige Umwandlungsausnahme aus
System.InvalidCastException: 'Objekt dieses Typs kann nicht umgewandelt werden „Microsoft.Data.SqlClient.SqlCommand“ zum Typ „System.Data.SqlClient.SqlCommand“.
Aber diese Befehle laufen ohne Probleme in meiner Web-App.
Könnte Hilft mir jemand, dieses Problem zu lösen?
Eine .csproj-Datei:
Code: Select all
…
Exe
netcoreapp2.1
…
…
…
Code: Select all
using System;
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using System.Collections.Generic;
…
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder
.UseSqlServer(connectionString, providerOptions => providerOptions.CommandTimeout(60));
using (fmDataContext context = new fmDataContext(optionsBuilder.Options))
…
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
…
DataTable dt = new DataTable();
DbConnection connection = Database.GetDbConnection();//)
using (DbCommand cmd = connection.CreateCommand())
using (DbDataAdapter sda = new SqlDataAdapter((SqlCommand)cmd))
{
cmd.CommandText = sqlQuery;
cmd.CommandType = CommandType.Text;
connection.Open();
rows_returned = sda.Fill(dt);
connection.Close();
}