Connection string Error when trying to make Installation - winforms

I made EntityFramework (6) CodeFirst WinForms application
On my machine it works fine but when I'm trying to make Installation (with VS 2015 Installing projects) of my project and to run it on another machine, I get Expansion of Data Directory failed
I'm really dont understand- when I'm trying to change db name in ConnectionString to some wrong name- it still works.
My connection string in app config:

I found what was the problem. It is not enough to pass the name of connection string via Entity context constructor :base(ConnectionString). Entity context name MUST be the same as Connection string in app config. Other way EF create some another db.

Related

SSIS to Oracle "Could not create a managed connection manager."

I'm trying to use SSIS to load some data from Oracle database to MSSQL database.
I created the project and used the ADO.Net source and was able to create a connection to Oracle and run queries and view results.
However when I actually run the package I get the following error:
Error: 0xC0208449 at Data Flow Task, ADO NET Source 2: ADO NET Source has failed to acquire the connection {EECB236A-59EA-475E-AE82-52871D15952D} with the following error message: "Could not create a managed connection manager.".
It seems similar to the issue here
And I did find that I have two oracle clients version installed "11.1" and "12.2".
One is used by PL/SQL and the other by other entity framework project.
If this is the issue I just wanted a way to tell the SSIS to pick-up the correct one.
I tried adding Entry in machine.config for "oracle.manageddataaccess.client" section with the desired version.
I also tried using other types of data sources but couldn't even create a successful connection
I tried changing the Run64bitRuntime property in the project to False
Note: I don't have SSIS installed on my machine.
Eventually, I just had to remove the entries related to 11.1 in path variable then restarted my machine.
Also I switched to "dotConnectForOracle" for connection and now it seems to be working fine.
I'm expecting issues related to other applications that might still be using the 11.1 version, but that will be a problem for another day.
Always make sure to write the user (oracle schema) in uppercase and some special characters [in my case it was $] in the password needs escape character even if you're using the wizard not the cmd
I still don't understand the whole issue but I hope this helps someone some day.

Connection string in appsettings.json for remote database

I have hosting account in plesk panel. I can create and remove a database in hosting panel.
Now I want to create a database from my local computer using add-migration in code first approach. but the following error occurs:
"login failed for the user [myUserId]"
The connection string in appsettings.json is:
"CourseConnection": "Data Source = host-ip,1433; Initial Catalog=mydb;User ID=myuserid;Password=mypassword"
There are two options to create databases on hosting panel:
localhost:3306(default for mysql)
localhost(default for MS sql v13.0...)
I think that provider name is not mentioned in connectionstring but appsettings.json works fine on my local machine without provider name: System.Data.SqlClient.
after hours of try and error , the problem solved as follows:
i created the database in plesk panel and created a new user .
then assign that user to the database . then in package-manager-console applied update-database command to apply migration that was already added.
i used the same connection string in appsettings.json ,it worked successfully.all table created and migration applied .
it may be helpful for someone.
regards

SQL Server connection failing with LinqToSQL but working with EF 6

I have an application (.NET WPF LinqtoSQL) that works when I connect to a local database. When I changed to a database on a different server I get an error (SQL Server Instance not found error 26).
The solutions to this error are all based on the server, firewall, and making sure SQL Server Browser is up and running, none of which I can do because I have no rights on the server.
But I created a small test application using WPF and EF (ADO.NET) that successfully connects to the exact same database (and table). I have no clue what might be going on, but I am not sure I want to re-write the application using EF (at least right now).
Does anyone understand the difference between the framesworks' connection method to point me to a possible solution for the LinqToSQL version beyond waiting for the IT guys to "fix" the server?
Given the revelation above that EF and L2S use the same connection class I figured a new project that points to the new server would fix my issue. And it did:
I created a new project, added a new L2S item, and then copied in all of my old projects views/ viewmodels/ etc. and it runs just fine.
I thought I could simply update the connection string, as this is what I believe I have done successfully in the past, but perhaps there is something else had to be set somewhere in the project settings or generated DataContext code to the new server. If anyone knows what that is please answer and I'll accept it.

The underlying provider failed on ConnectionString (|DataDirectory| and LocalDB)

I'm getting the exception
The underlying provider failed on ConnectionString.
with inner exception
Invalid value for key 'attachdbfilename'
on a windows 7 home premium virtual machine as i'm trying to deploy and debug my application.
However, on my development machine, the application just launches without problems.
the connection string is :
<add name="AssetsLocalDBEntities" connectionString="metadata=res://*/AssetsLocalDB.csdl|res://*/AssetsLocalDB.ssdl|res://*/AssetsLocalDB.msl;provider=System.Data.SqlClient;provider connection string="data source=(localdb)\v11.0;attachdbfilename=|DataDirectory|\AssetDatabase.mdf;initial catalog=AssetDBSource;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Steve Wellens has mentioned that the connection string contains garbage in this topic:
The underlying provider failed on ConnectionString
yet, as Maxim Gueivandov has replied, this should valid connection string, as it's directly generated by the EntityFramework's edmx designer.
At least, i believe it to be valid, as it does work on the development machine.
Also in another topic (Entity Framework - The underlying provider failed on ConnectionString), the accepted answer is to remove the " and replace them by \", as the string is a literal in the c# code, yet i still have my connection string in xml, so " cannot simply be replaced.
on-connectionstring
The .NET version installed on the virtual machine is 4.0.30319 and MsSQL Server Express LocalDB is 11.0.2318.0, so i believe they are both up to date.
Edit: If i remove "|DataDirectory|" from the connection string i get the following error on my development machine:
Cannot attach the file 'AssetDatabase.mdf' as database 'AssetDBSource'.
So i also remove "initial catalog=AssetDBSource" and i get
An attempt to attach an auto-named database for file AssetDatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
i can emagine this is because it doesn't know where to look? so, i provide it the full path (C:..\AssetDatabase.mdf) and it works.
So the remainder of the question is: how do i get relative paths working with LocalDB?
I believe the target machine doesn't have the Update 4.0.2 or later for .NET 4 installed. The .NET 4 version number can be confusing, as version 4.0.30319 seems to be used by all .NET 4 builds. In effect it does not mean your machine has the Update 4.0.2.
Can you install .NET 4 Update 4.0.3 (latest .NET 4 update as of today) on the target machine and see if the problem goes away?
Or just verify that the update is installed - just build a simple application in .NET 4 that uses SqlClient to connect to LocalDB using the connection string, and record the error information in case you still hit any errors. The EF error message is fairly generic, and I don't know how to get a detailed error from the underlying SqlClient provider.
Alternatively you could also migrate it to .NET 4.5.

EF Code first after deployment throws ProviderIncompatibleException

I have a simple EF 5.0 / Code First application developed in VS2012. In development it uses SQL Server CE. However, when I deployed it on a test server, I am getting the following stack of errors:
ProviderIncompatibleException: An error occurred while getting provider information from the database.
This can be caused by Entity Framework using an incorrect connection string.
Check the inner exceptions for details and ensure that the connection string is correct.
ProviderIncompatibleException: The provider did not return a ProviderManifestToken string
SqlException (0x80131904): Login failed for user 'MYDOMAIN\MYSERVER$'
IIS and the database are on the same server (MYSERVER). It's running Win2012, (with IIS 8 and .NET 4.5) and SQL Server 2012.
There are two things in web.config that caught my attention. First, connection string. I generated it from IIS UI; and I used my old connection strings that had "Data Source", rather than server. I used localhost and server name. I created a db user. I read somewhere that the database doesn't exist - so I deleted it. I gave permissions to NT AUTHORITY\NT SERVICE in the database. I probably did some other permutations - but the result is always the same.
The second place was Connection Factory under entity framework section. Apparently, it wasn't changed by Web Deploy; type was still SqlCeConnectionFactory, and parameter was System.Data.SqlServerCe.4.0. I saw somewhere that SQL Server was the default - so I deleted it; and when that didn't work, I changed the values to SqlConnectionFactory and System.Data.SqlServer correspondingly - but again, result is the same.
By now I ran out of ideas... Given that I have a problem even when I am reading the data from existing database - I am missing something simple...

Resources