I am relatively new to Visual Studio and I figured the best way to proceed would be to [sarcasm] do a major project [\sarcasm].
Summary of work to be done here:
VS2008 -> VS2012
Windows7 -> Windows8
SQL CompactServer v3.5 -> SQL CompactServer v4.0
.NET Framework v2.0 -> .NET Framework v4.0
One of the problems I am running into is that even though I have migrated my DB file in VS from SQL_CE_v3.5 to SQL_CE_v4.0 and updated my references to System.Data.SqlServerCe (4.0), I am getting the following exception when an attempt to open the db file is made the following way.
DB.DataContext = new DB.DataContext(CONNECTION_STRING);
Exception:
System.InvalidOperationException: Cannot open '|DataDirectory|\Database.sdf'. Provider 'System.Data.SqlServerCe.3.5' not installed.
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Initialize(IDataServices dataServices, Object connection)
at System.Data.Linq.DataContext.Init(Object connection, MappingSource mapping)
at System.Data.Linq.DataContext..ctor(String fileOrServerOrConnection, MappingSource mapping)
.
.
.<br>
Question:
How can I change the provider name here to 4.0 instead of 3.5?
What would be the best way to do all these migrations?
Initialze the DataContext object with a SqlCeConnection object, not a connection string, so something like:
DB.DataContext = new DB.DataContext(new SqlCeConnection(CONNECTION_STRING));
Related
I used the database first approach.
The model is right (or at least it looks like)
But I always get this error. Please, I've already tried so many things..
The full code of my program (and even sql script by which I create my database)
is here: https://github.com/AntonioParroni/test-task-for-backend-stack/blob/main/Server/Models/ApplicationContext.cs
Since I have a mac. I created my model with dotnet ef cli commands (dbcontext scaffold)
I can use my context. But I can't touch any DbSet..
public static void Main(string[] args)
{
using (ApplicationContext context = new ApplicationContext())
{
Console.WriteLine(context.Database.CanConnect());
var months = context.Months.ToList();
foreach (var month in months)
{
Console.WriteLine(month.MonthName);
}
}
//CreateHostBuilder(args).Build().Run();
}
It is not my first time using EF. And everything was working fine before, in many simple projects or tasks. While here.... It doesn't matter what I do (I even tried to rename all of my columns name, erase all tables except one, modify the context code, use the same steps from this project on a new, totally empty project..)
It is always..
Unhandled exception. System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
---> System.InvalidOperationException: Sequence contains more than one matching element
at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException() in System.Linq.dll:token 0x600041c+0xa
ect....
Here is my package reference file
"restore":{"projectUniqueName":"/Users/mac/Documents/GitHub/test-task-for-backend-stack/Server/Server.csproj",
"projectName":"Server","projectPath":"/Users/mac/Documents/GitHub/test-task-for-backend-stack/Server/Server.csproj",
"outputPath":"/Users/mac/Documents/GitHub/test-task-for-backend-stack/Server/obj/","projectStyle":
"PackageReference","originalTargetFrameworks":["net6.0"],"sources":{"https://api.nuget.org/v3/index.json":{}},
"frameworks":{"net6.0":{"targetAlias":"net6.0","projectReferences":{}}},
"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net6.0":
{"targetAlias":"net6.0","dependencies":{"EntityFramework":
{"target":"Package","version":"[6.4.4, )"},
"Microsoft.EntityFrameworkCore.Design":{"include":"Runtime, Build, Native, ContentFiles, Analyzers, BuildTransitive",
"suppressParent":"All","target":"Package","version":"[5.0.0, )"},
"Microsoft.EntityFrameworkCore.SqlServer":{"target":"Package","version":"[5.0.0, )"},
"Swashbuckle.AspNetCore":{"target":"Package","version":"[5.6.3, )"}},
"imports":["net461","net462","net47","net471","net472","net48"],
"assetTargetFallback":true,"warn":true,
"frameworkReferences":{"Microsoft.AspNetCore.App":{"privateAssets":"none"},
"Microsoft.NETCore.App":{"privateAssets":"all"}},
"runtimeIdentifierGraphPath":"/usr/local/share/dotnet/sdk/6.0.100-preview.6.21355.2/RuntimeIdentifierGraph.json"}}
It's been already a few days. And I'm becoming really confused and mad.
Why is this happening.. and why there is not that much info about this type of error in the internet. Please, just point me in the right direction..
You have net6.0 target framework which is still not released while you have installed EF6 which is a previous iteration Entity Framework (mainly used with legacy .NET Framework projects) and you also have EF Core (a modern iteration of it) but older version - 5.0 (which you are actually using for your context, see the using Microsoft.EntityFrameworkCore; statements there).
Try removing EntityFramework package and installing preview version of Microsoft.EntityFrameworkCore.SqlServer (possibly just updating to the latest 5 version also can help) and either removing completely or installing preview version of Microsoft.EntityFrameworkCore.Design. (Also I would recommend to update your SDK to rc and install rc versions of packages).
Or try removing the reference to EntityFramework (not Core one) and changing target framework to net5.0 (if you have it installed on your machine).
As for why do you see this exception - I would guess it is related to the new methods added to Queryable in .NET 6 which made one of this checks to fail.
TL;DR
As mentioned in the comments - update EF Core to the corresponding latest version (worked for 5.0 and 3.1) or update to .NET 6.0 and EF Core 6.
I'm trying to connect to our Snowflake DB using SSO with the ff connection string but keeps on getting an error. I'm using https://github.com/snowflakedb/snowflake-connector-net for my .NET 4.6.1 console application just to test things out. I have confirmed that my SSO is able to login to the Snowflake Web UI. Found related docs: https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use.html#native-sso-okta-only
connection string:
AUTHENTICATOR=https://{okta_account_name}.okta.com;ACCOUNT={org}.{region};HOST={org}.{region}.snowflakecomputing.com;PORT=443;ROLE={role};WAREHOUSE={warehouse};USER={sso email};password={sso password};DB={db};SCHEMA={schema}
error:
Exception: Error: Connection string is invalid: Unable to connect SqlState: 08006, VendorCode: 270008, QueryId:
Maybe I posted a question too soon. Following the Readme.md for Snowflake Dotnet Connector, I was able to generate the logs thru log4net. The underlying exception was
[2021-08-11 23:09:04,732] [1] [ERROR] [Snowflake.Data.Core.SFSession] Unable to connect
System.PlatformNotSupportedException: Operation is not supported on this platform.
at Snowflake.Data.Core.HttpUtil.setupCustomHttpHandler(HttpClientConfig config)
at Snowflake.Data.Core.HttpUtil.<>c__DisplayClass10_0.<RegisterNewHttpClientIfNecessary>b__1()
at Microsoft.Extensions.DependencyInjection.HttpClientBuilderExtensions.<>c__DisplayClass5_0.<ConfigurePrimaryHttpMessageHandler>b__1(HttpMessageHandlerBuilder b)
at Microsoft.Extensions.Http.DefaultHttpClientFactory.<>c__DisplayClass17_0.<CreateHandlerEntry>g__Configure|0(HttpMessageHandlerBuilder b)
at Microsoft.Extensions.Http.LoggingHttpMessageHandlerBuilderFilter.<>c__DisplayClass3_0.<Configure>b__0(HttpMessageHandlerBuilder builder)
at Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateHandlerEntry(String name)
at Microsoft.Extensions.Http.DefaultHttpClientFactory.<>c__DisplayClass14_0.<.ctor>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateHandler(String name)
at Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateClient(String name)
at Snowflake.Data.Core.HttpUtil.GetHttpClient(HttpClientConfig config)
at Snowflake.Data.Core.SFSession..ctor(String connectionString, SecureString password)
After browsing the web with similar exception it was mostly about the target .NET framework not satisfying the requirement. I was initially targeting .NET Framework 4.6.1 but after changing it to 4.7.2 everything worked fine as expected. It was indeed mentioned on the repo that the driver is now targeting 4.7.2 but I don't recall seeing it being unable to support lower framework versions. I tried downgrading the driver to the earliest version and upgrading it to the latest one by one with no avail. Hope this help others facing the same issue.
Based on my experience with Snowflake.Data, it supports .Net framework starting from version 4.6.1.
The connection string is like:
connStr="scheme=https;account=youraccount;host=xxx.snowflakecomputing.com;port=443;proxyhost=xx.myproxy.com;proxyport=80;role=MY_ROLE;warehouse=WAREHOUSE_NAME;user=userid;password=xxx;authenticator=xxx.okta.com"
You may also try to set authenticator=externalbrowser.
I personally prefer to connect to Snowflake using ODBC Driver. Please refer to https://docs.snowflake.com/en/user-guide/odbc.html on how to install ODBC driver in your local machine. Once you install and configure Snowflake in your machine, you may connect to Snowflake using System.Data.Odbclibrary.
The connection string might looks like:
connStr="Dsn=DataSourceName;uid=userID;pwd=xxx"
You may also try browser-based SSO:
In the connection string, set AUTHENTICATOR=externalbrowser, and set USER to the login name for your IdP.
using (IDbConnection conn = new SnowflakeDbConnection())
{
conn.ConnectionString = "account=testaccount;authenticator=externalbrowser;user={login_name_for_IdP};db=testdb;schema=testschema";
conn.Open();
conn.Close();
}
where:
{login_name_for_IdP} is your login name for your IdP.
I created ASP.Net web application in Visual Studio 2019.
This application uses Sybase.AdoNet2.AseClient.dll to connect to Sybase database.
InnerException = "Could not load C:\Users\....\AppData\Local\Temp\Sybase.AdoNet2.AseClient.32bits.2.157.1410.0\sybcsi_openssl210.dll"
the project target framework is .Net Framework 4.5
How do fix this issue?
First, you need to install nuget package -> AdoNetCore.AseClient.
Then, please use using AdoNetCore.AseClient; in the top of code.
Finally, you can use the following code without any exception.
AseConnection connection = new AseConnection();
Besides, we need to note that we have to use .net core app because the limit of AdoNetCore.Aseclient.
Finally i use the old version 2.157.1000.0 to Fix this problem.
I am trying to open a connection to a Firebird database in my c# asp.net web application. It throws an error "The type initializer for 'FirebirdSql.Data.Common.TimeoutHelper' threw an exception."
I am new to Firebird.
In web.config I have:
<add name="FireBirdConnectionString" connectionString="Server=localhost;User=SYSDBA;Password=masterkey;Charser=NONE;Database=D:\data\SAMPLE.fdb" providerName="FirebirdSql.Data.FirebirdClient"/>
I have installed FirebirdSql.Data.FirebirdClient-4.5.1.0 and have added a namespace of
using FirebirdSql.Data.FirebirdClient;
I am opening the connection like below:
using (FbConnection con = new FbConnection(conString))
{
con.Open();
}
But this shows me an error as The type initializer for 'FirebirdSql.Data.Common.TimeoutHelper
What am I doing wrong?
I need to open the connection.
Even in connection string
and I have that path in my desktop too
Thank You..!
As I commented earlier, you are probably using the .NET 4.5 version in a .NET 4 project. You either need to switch your project to .NET 4.5 (which requires Visual Studio 2012 or 2013), or you need to replace the FirebirdSql.Data.FirebirdClient library with the .NET 4 version.
I'd suggest you use NuGet to install it, as this will verify - install time - which variant you need. Otherwise you need to pick the second link from http://www.firebirdsql.org/en/additional-downloads/ (iirc the first link only installs and includes the .NET 4.5 version).
Hi I use the following code to connect to an orace database in Visual Studio 2008 and it is falling over with the exception of ServerVersion threw an invalid operation exception at line 3:
m_strConnectionString = Settings.GetMandatoryConfig("databases", "SourceDB");
m_strQueryTerminator = Settings.GetConfig("databases", "QueryTerminator");
m_odbConn = new OleDbConnection(m_strConnectionString);
m_sql = new SQL(DatabaseType.AnsiSQL, false);
m_strConnectionString is a valid TNS names connection string and is as follows:
Provider=MSDAORA;Data Source=myDS;User
ID=myID;Password=myPW
This has previously worked and is using an IIS web server to host the application. I recently converted it from .Net 1.1 (VS 2003) to .Net 3.5/2 (VS 2008) and can't get it working as yet in VS 2008.
Thanks
Maybe you should consider using the OracleConnection class instead of the generic OleDbConnection. Doing this may give you more specific error information that what you're receiving now - and could help you find your problem quicker.
See here for more information on the System.Data.OracleClient namespace included with the .Net framework.