The underlying provider failed to open , login failed for user IIS APPPOOL - sql-server-2008

i am not a sql server guy but i am working on a client's application and want to connect to the database through EF Code first
the Exception message that i have is
The underlying provider failed to open
The Exception details
Cannot open database [DatabaseName] requested by the login. the login failed
login failed for user 'IIS APPPOOL\ASP.NET v4.0"
My web config
<add name="TraininGoDB"
providerName="System.Data.SqlClient"
connectionString="Server=LOCALPCNAME\SQLEXPRESS;Database=[DATABASENAME];Integrated Security=True;"/>
The EF context and entities are defined in a separate project with the app config of the following
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
i am using SQL Server Express 2008
don't know the problem from the database configration or from the web config

The user under which the web application pool (associated to your web application) is running doesn't have permissions to access your database. You need to grant it permissions or run under another user who has permissions. So, to summarize: check under which user your application pool is running, then check that that user has access to your database.

If all of your Web.config files are correct, SQLSERVER has the appropriate permissions, etc., there's one more thing you can check. I once had this issue when a client had me configure the project so that Entity Framework would not automatically drop the databases (if, for example, the models changed), but I was still testing the project on localhost. I thus needed to create a new database, but I forgot to fix my context files. For example, my problem was:
public MasterContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
Database.SetInitializer<MasterContext>(null);
}
when it should have been (for the purpose of testing):
public MasterContext(string nameOrConnectionString) : base(nameOrConnectionString)
{
Database.SetInitializer<MasterContext>(new DropCreateDatabaseIfModelChanges<MasterContext>());
}
Otherwise, I would receive the same error, that the underlying provider failed on open, with the inner exception being that the login failed for the user.

Related

WSO2 API Manager Mysql database initialization

I'm trying to change the carbon H2 database (for this test) for a MariaDB system. Once my master-datasources.xml and my databases created and configured thanks to the provided scripts, I start the API Manager but it fails with the following error :
ERROR - Activator Cannot start User Manager Core bundle
June 1st 2018, 14:51:07.000 org.wso2.carbon.user.core.UserStoreException: Cannot initialize the realm.
Caused by: org.wso2.carbon.user.core.UserStoreException: nullType class java.lang.reflect.InvocationTargetException
June 1st 2018, 14:51:07.000 Caused by: org.wso2.carbon.user.core.UserStoreException: nullType class java.lang.reflect.InvocationTargetException
Caused by: org.wso2.carbon.user.core.UserStoreException: Error occurred while checking is existing domain : PRIMARY for tenant : -123
I tried to use MariaDB only for the carbon database, using the following datasource config:
<datasource>
<name>WSO2_CARBON_DB</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/WSO2CarbonDB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://wso2_mysql:3306/wso2_am_carbon;DB_CLOSE_ON_EXIT=FALSE</url>
<username>wso2carbon</username>
<password>wso2carbon</password>
<!--<driverClassName>org.h2.Driver</driverClassName>-->
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
user-mgt.xml is using the correct datasource name :
<Property name="dataSource">jdbc/WSO2CarbonDB</Property>
and my database has been initialized with the dbscripts/mysql5.7.sql script. User permissions have been set correctly.
Since after the failed start the database stays empty I guess there is a problem writing to it. So I tried to start the app with the -Dsetup parameter but no luck.
Thank you.
In the very first startup of the WSO2 server without the datasource changes, It will add an admin user to the default userstore. Therefore, if you have already created admin user within configured AD and that user has defined as admin user in IS configurations, IS use that user as the admin user.
Therefore, When you change the datasource of the primary userstore of WSO2 Server, you need to change the addAdmin property as true in user-mgt.xml file which can be found under /repository/conf directory.
<Configuration>
<AddAdmin>true</AddAdmin>
<AdminRole>admin</AdminRole>
<AdminUser>
<UserName>admin</UserName>
<Password>admin</Password>
</AdminUser>
-
-
</Configuration>
Please check after changing the above property.

Using MSSQL and MySQL database both as entity framework 6 model

I'm new to work with MySQL with asp.net and I'm trying to use asp.net mvc 4 and entity framework 6 to view datas from MySQL & MSSQL database both. So far MSSQL is working fine. But whenever I try to view datas from MySQL tables I get this error,
Schema specified is not valid. Errors: Models.MySqlModel.ssdl(2,2) : error
0152: No Entity Framework provider found for the ADO.NET provider with
invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered
in the 'entityFramework' section of the application config file. See
http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I've installed MySQL for Visual Studio 1.1.4 & MySQL Connector .NET 6.8.3, I've added MySql.Data, MySql.Data.Entity.EF5, MySql.Data.Entity.EF6 assemblies in the reference folder. This is my Web.Config code for db connection,
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ABCoLtd-20150101142609;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-ABCoLtd-20150101142609.mdf" />
<add name="mytestdbEntities" connectionString="metadata=res://*/Models.SampleModel.csdl|res://*/Models.SampleModel.ssdl|res://*/Models.SampleModel.msl;provider=System.Data.SqlClient;provider connection string="data source=DREAGLEASUS64\SQLEXPRESS;initial catalog=mytestdb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /><add name="mdsdata_demoEntities" connectionString="metadata=res://*/Models.MySqlModel.csdl|res://*/Models.MySqlModel.ssdl|res://*/Models.MySqlModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;password=4de570;database=mdsdata_demo"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
Code from Controller to view data from MySQL table,
namespace ABCoLtd.Controllers
{
public class HomeController : Controller
{
mytestdbEntities db = new mytestdbEntities(); //MSSQL Model
mdsdata_demoEntities dsedb = new mdsdata_demoEntities(); //MySQL Model
public ActionResult InstrumentList()
{
return View(dsedb.mkistats.ToList()); //The Line showing error
}
}
}
Am I doing something wrong here? I need this help badly. Please help me, your help will be really appreciated. Tnx.
UPDATE
When I see them in Reference Manager it says 6.8.3.0 but in Properties I get 6.8.4.0. Is it the possible bug? If it is, what is the solution? See the images below,
Check if you installed correct bit version and enable 32-bit applications in IIS.
And try to delete one of either references

code first -The provider did not return a ProviderManifestToken string

I wrote a windows form solution with 2 layers; one is DataAccess and the other is windows form.
I use Code first. If DataAccess Layer runs in the application console, there is no problem with the db. Create the schema and insert the data.
However, when I run the solution with Windows Form as the initial project and refer to DataAccess as a dll, I cannot build the database. It throws an exception.
I think that the app.config file is the problem, but if I copy the app.config file of DataAccess project to the windows form, it does not resolve the problem.
the config file of DataAcces layer:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
the exception:
"first exception for 'System.Data.Entity.Core.ProviderIncompatibleException' in EntityFramework.dll
Aditional Information: 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."
Inner Exception:
{"The provider did not return a ProviderManifestToken string."}
The problem could be due to Error in connection string
or in my case it was that
SQL server service was not running
manually start the SQL service through SQL SERVER COnfiguration Manager
after a long deep search, i found that solution was "clean the solution".

Entity framework with MySQL

hello i installed MySQL Connector/Net 6.7.4 so i was able to generate edmx from my MySql database, but now i wanna do smth with it so i added connetion string and :
<DbProviderFactories>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
in my webconfig, but when i create context(pure generated by .tt) i got an exception on collection:
The specified store provider cannot be found in the configuration, or is not valid.
Any ideas why? I already added MySql.xxx dlls to my bin
Edit: connstring was wrong when i modified provider name so it looks now:
<connectionStrings>
<add name="classicmodelsEntities" connectionString="metadata=res://*/mysql.Model1.csdl|res://*/mysql.Model1.ssdl|res://*/mysql.Model1.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;password=Password;persist security info=True;database=classicmodels"" providerName="MySQL Data Provider"/>
i got exception :Unable to find the requested .Net Framework Data Provider. It may not be installed.
If you are using Entity Framework, why are you adding a connection string? The connection string generated for me was different:
<add name="stuffEntities"
connectionString="metadata=res://*/Entities.MyModel.csdl|res://*/Entities.MyModel.ssdl|res://*/Entities.MyModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=myserver.com;user id=my_user;password=my_password;persistsecurityinfo=True;database=db_example""
providerName="System.Data.EntityClient" />
Add your MySQL references on References, with True for Local copy. Also add the required configuration in Web.config, installing through NuGet the missing package.
To do this, right click your solution or project, click on Manage NuGet packages, and install the missing MySQL.Data reference. This should modify your Web.config with the reference.

Cant get my connection to a MySQL from asp.net mvc project to work

I am trying to get MVC 3 Application to use a MySql database, but I keep getting errors, I have made the following connectionstring and provider in my Web.Config file
<connectionStrings>
<add name="DefaultConnection" connectionString="server=xxxxx.unoeuro.com; userid=xxxxx_dk;password=xxxxx;pooling=yes;Database=xxxxx_dk_db" providerName="MySql_db"/>
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="MySql_db" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.1.54.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
But when I try to use it (Just trying to use the default register user that is in a default project) I get this error
An error occurred creating the configuration section handler for
system.data: Column 'InvariantName' is constrained to be unique.
Value 'MySql.Data.MySqlClient' is already present.
But I if I remove the DbProviderFactories I just get an error that there is missing a data provider, so its not becuase I duplicated it anywhere
Building upon #Ladislav Mrnka's answer, the error is probably occurring because the setting in Web.config is conflicting with one in machine.config. To eliminate the error, add a "remove" tag to your Web.config as follows.
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySql_db" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.1.54.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
Provider name in connection string must be set to invariant name of provider factory. Also the error most probably says that you already have MySql.Data.MySqlClient installed on your machine and registered in Machine.config.
Install the latest version of MySQL for visual studio and find a compatible version for Connector/NET.
For example, I have used MySQL for Visual Studio 1.2.7. and Connector/NET 6.7.5, 6.8.3 or 6.9.x. for Visual Studio 2013
uninstall all the other versions of MySQL for visual studio and Connector/NET.
After that Add new item-> ADO.Net Entity Data Model and create the edmx file.
you can see system.data and system.data.entity in your reference folder of the project.
In your code
MyDatabaseEntities myDB = new MyDatabaseEntities();
use myDB to access your data.
If you are creating a framework project, copy everything under tag from app.config and paste it into your main project's(startup project) web.config file
One thing needs to keep in mind that this tag should be the first child of tag.