use of universal providers and mysql - mysql

I created an asp.net mvc 4 application, and added universal providers, because I need to create a custom membership provider that read users data from a my sql database.
When I work on the developer workstation it's all ok, but when I deploy on the server, where there is not Sql Server installed i receive an error. trying to open DefaultConnection.
In the InitializeSimpleMembershipAttribute that is created from the wizard, I have this:
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: false);
this call initialize the db connection, do nothing, and is not used by the custom membership provider, but must be done at startup.
the connection string is:
add name="DefaultConnection" connectionString="Data Source=...;Initial Catalog=...;User id=...;Password=..." providerName="System.Data.SqlClient" />
the problem is that I don't know how to configure to use a mysql db and pass this control in the startup of the application.
If I have to install it in a server with Sql server installed, I configure it properly, and after the initial call the mysql membership provider works without problem, but i have problems when i cannot use this workaround, and exception is raised at the call to InitializeDatabaseConnection.
How can I fix this problem?

Related

Sql login failed in dotnetnuke(dnn)

I am trying to install dotnetnuke in my localhost but not able to installing dnn and below connection string used in webconfig file.
<add name="SiteSqlServer" connectionString="Server=(local);Database=d1;uid=;pwd=;" providerName="System.Data.SqlClient" />
Below error getting:
I am installing dnn in local host, please help to out this headache installation.
Integrated will attempted to use Windows Authentication for the database connection.
You either need to create a SQL authentication account and choose the "User Defined" option, or you need to add the user for your app pool to SQL to give it access to the D1 database.
I prefer to just use SQL Auth accounts, always ends up easier in my opinion.

AppHarbor: Connecting to a MySQL DB via ASP.NET MVC 5 + Dapper

I'm trying to get an application up and running on AppHarbor. It's been smooth sailing for the most part, but today I'm having trouble connecting to my MySQL database.
Using the credentials AppHarbor provided me with, I successfully connected to the mySQL database instance using dbForge Studio Express, created the necessary SQL schema, and populated the tables with data. Now I'm trying to use the following C# code to do a simple query using Dapper:
var sqlConnStringBuilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString);
using (var db = new SqlConnection(sqlConnStringBuilder.ConnectionString))
{
db.Open();
// Do database query stuff
return result;
}
But this is the error that I'm running into, when I try to open the database connection:
An exception of type 'System.Data.SqlClient.SqlException' occurred in
System.Data.dll but was not handled in user code
Additional information: A network-related or instance-specific error
occurred while establishing a connection to SQL Server. The server was
not found or was not accessible. Verify that the instance name is
correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)
This is how I've declared the connection string in Web.config:
<connectionStrings>
<add name="AppHarborMySql" connectionString="server=MYDOMAIN.mysql.sequelizer.com;database=MYDBNAME;uid=MYUSERNAME;pwd=MYPASSWORD" providerName="System.Data.SqlClient" />
</connectionStrings>
Am I missing something obvious? I'm using ASP.NET MVC 5.x and the latest version of Dapper... thanks in advance!
And of course, despite having spent the better part of an hour investigating, I discover the answer immediately after posting the question.
For anyone else who may run across the same problem: I added the MySql.Web NuGet package to my MVC project, added using MySql.Data.MySqlClient; to the top of my page, and then changed my code to point from SqlConnection to MySqlConnection. Here's what my working code block now looks like:
using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString))
{
db.Open();
// Do database query stuff
return result;
}

Database Migrations in VS2012(MVC 4) from default SQL Express LocalDb)v11.0 to MySQL

I am currently facing a issue of how to migrate the database for user information which is created by default in VS 2012. When I create a project, a LocalDb\v11.0 is created with all user tables and database.
In my application I want to use MySQL as database. I am able to run, connect and access MySQL database running on MySQL workbench. But I am facing this issue of how to migrate User Access Controls i.e, Account Controllers and Home Controller are already given; Currently when I press on Login I am redirected to a page to enter my login credentials. Which uses this default SQL Express LocalDb.
I want to use the code functionality which is provided to me by Microsoft but want to use a MySQL database.
I am currently thinking of migrating from default SQL db in which Account/user tables are, to MySQL and then operate code with MySQL database. There is no specific post which targets this issue. I am really clueless now, can someone give some pointers as of where to start?
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ImageRepository-20140121114624;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-ImageRepository-20140121114624.mdf" providerName="System.Data.SqlClient" />
I am thinking of making this Default Connection to point to mySQL Db that I have but this is not working.
you will need to modify your connection string to connect to your mysql database.
you will find more info here
mySQL DataSource on Visual Studio 2012
if you are using entity framework in your project it will be compatible with mysql.

Ef code first migrations on server:Cannot open database "blahblah" request by the login. The login failed

There are a million threads like this but none where the answers worked.I'm trying to get this database set up on my server (which I can remote into), but every time I try and run the web app I get this error. Why is code first not creating the database? Here's some relevant code.
Connection string in web.config
<add name="Context" connectionString="Data Source=Server\Instance;Initial Catalog=myDb;Trusted_Connection=false;User Id=User;Password=password;" providerName="System.Data.SqlClient" />
Global.asax relevant portion
Context context = new Context();
Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>());
context.Database.Initialize(true);
if (!WebMatrix.WebData.WebSecurity.Initialized)
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection("BaseContext",
"UserProfile", "UserId", "UserName", autoCreateTables: true);
you're using integrated Windows authentication, you need to create a SQL Server login for "yourUser\ASPNET" on your SQL Server - or change your connection string to something like :
<add name="Context" connectionString="Data Source=Server\Instance;Database=myDb;Id=User;pwd=password;" providerName="System.Data.SqlClient" />
The login failed error is inside sql server error. Try if you have SQL Managment Studio logged using your data in connection string - Context.
I only thinking, but when you migrating your database recreate your user sql account and rester sql server.
Or
Try create new user by SQL Managment studio and then try usgin this data to connection string.
Check when you create user account, is not checked user must changed password first time.
I think my idea resolved your problem :)

MVC 3 - After publishing to server - CREATE DATABASE permission denied in database 'master'

Setup
MVC 3 EF 4.1 Code First - Windows 7 Pro 64 Dev machine, Separate Win 7 Pro for host.
I started with a SQLCE4.0 database, and everything worked fine (database initializer created tables, populated, etc...).
Once I got everything working like I wanted, I scripted out my SqlCe DB, created a real SQL 2008 DB, opened the proper ports and enabled TCP connections.
Problem
IF I Change my connection string to point to my intranet server\instance name, with a user I created for this app specifically, it works perfectly running from my dev machine.
IF I publish the app to the server (the web server and sql server are the same), and I try to login to the website (aka access the db), then I get:
CREATE DATABASE permission denied in database 'master'.
I commented out the DBInitializer setup so nothing should be created upon a db hit. The tables are there already.
If I do Database.SetInitializer(null); then I get a different login error:
I don't remember exactly but it was something to the affect of LOGIN FAILED FOR IIS APPPOOL\ApplicationPoolIdentity
So I changed the Identity to NETWORK SERVICE and even tried LOCAL SERVICE, both giving the same login failed error.
I tried following this post who says add a SQL user named 'IIS APPPOOL\MyApplicationName'. SQL Wont let me do that as it has invalid characters ... go figure.
Why does it work perfectly over the network accessing the DB from my dev machine, but when I publish to THE SAME machine that hosts the sql and the site, I get permission denied or login failed errors? I've scoured the net and tried different things.
EDIT: Here are my connection strings:
<add name="AntripContext" connectionString="Data Source=|DataDirectory|AntripWeb.sdf" providerName="System.Data.SqlServerCe.4.0" />
<!--<add name="AntripSQL" connectionString="Data Source=.\sqlexpress;Initial Catalog=Antrip;User Id=myuser;Password=mypassword;" providerName="System.Data.SqlClient" />-->
<add name="AntripWebEntities" connectionString="metadata=res://*/DAL.AntripEntities.csdl|res://*/DAL.AntripEntities.ssdl|res://*/DAL.AntripEntities.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\AntripWeb.sdf"" providerName="System.Data.EntityClient" />
<!--<add name="AntripWebEntities" connectionString="metadata=res://*/DAL.AntripEntities.csdl|res://*/DAL.AntripEntities.ssdl|res://*/DAL.AntripEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\sqlexpress;Initial Catalog=Antrip;User Id=myuser;Password=mypassword;"" providerName="System.Data.EntityClient" />-->
Note: The commented out connection strings are the ones that use the sql 2008 database (that break my published app).
It sounds to me as if your connection string has Integrated Security=true so that you are connecting to SQL as the user you specify, rather than the SQL user you think you are using?
But beware, its still trying to create a database: you need to swap the IDatabaseInitializer - I guess it will look for a DB named the same as the entitys to be careful!