How to Connect to MYSQL database in c# MVC website? [duplicate] - c#

This question already has answers here:
How to connect to a MySQL Data Source in Visual Studio
(13 answers)
Closed 6 years ago.
I currently run a PHP website which uses MYSQL for the database but now I what to move the website to MVC .Net environment but can't figure out how to this is what I am trying:
I Installed MYSQL.data.Entity, EF, and Web through Nuget package
then I added the connection string in the web.config file:
<connectionStrings>
<add name="constr" connectionString="Data Source=localhost;Initial Catalog=SampleDB;User Id=root;password=''"/>
</connectionStrings>
Password is left empty because there is no password on the database as I running it locally to test it
after all that I still cant view the Database I Server Explorer? should I be able to view the database in server explorer?
How can I make it work?
(also note I took the live database and put it into local)

You are not mentioning the mySql Connector for .NET. https://dev.mysql.com/downloads/connector/net/
Install it and it should start working ;)

Related

When installed on other PCs, C# WPF application (using entity framework) crashes while accessing local Database

I'm a newbie at wpf/c# and I developed an app connected to a local SQL server database using entity framework 6. I then made an installable for the app and tested it on different computers. It worked perfectly only on computers that have the same tools I used (Visual studios + Entity framwork tools). On other computers however, it crashes while trying to connect to the database.
On these computers, I installed the right version of .NET framework, and Sql Server LocalDB, to no avail.
Here's my connection string just in case:
<add name="bdd2Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\bdd2.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I found some similar subject : Entity framework application crashing on other system,
I hope someone here can find a solution to my problem. Thank you.

How to deploy C# windows application (setup file) with database and how to manage connection string on client machine

I am creating C# Windows Application in Visual Studio 2015.
Question:
How to deploy C# Windows Application (setup file) with SQL Server database with database connection string.
I create common connection string in app.config :
<connectionStrings>
<add name="conString"
providerName="System.Data.sqlclient"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=
'C:\Users\DEVELOPERS\Documents\Visual Studio 2015\Projects\Provision1\
Provision1\provision1.mdf';Integrated Security=True"/>
</connectionStrings>
Now connection string path location shows my machine.
Then after installation .exe how to connect database and how to manage connection string on client machine.
The easiest way you can do is:
Save your connection string in app.config is absolutly common
Compile your Project with Release settings
Take your .exe file from /bin/release/.. Folder
The Database should be connected via the connection string. If the database is not connected via network you need to deploy it as well.
Make sure your clients have .Net Framework installed
If you definitive need a setup.exe which installs your software, you can make a new project which is of type setup-programm. Watch this link for description.
If you don't want your users to see the connectionstring you can use a ConnectionStringBuilder. Save just a part of your connection string to app.config and build the rest via Quellcode. Watch this MSDN-Article.

Unable to connect to LocalDB during webhosting [duplicate]

This question already has an answer here:
appharbor connection string
(1 answer)
Closed 7 years ago.
I am using asp.net identity with EF data first approach. Everything is working fine on localhost. I have hosted my website on appharbor. All of my controllers actions and webapi is working fine except AccountController. When a user tries to signup it gives the Internal server error. The details of error is:
Note: My database queries are working fine. It means there is no issue in connection string.
And to enable remote connections SQL Server Network Configuration does not has the option Protocols for SQLEXPRESS
How can I tackle this issue?
Update:
My connection strings in web.config are:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-Inspinia_MVC5_SeedProject-20141215093835.mdf;Initial Catalog=aspnet-Inspinia_MVC5_SeedProject-20141215093835;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Server=b1ad1f3e-1ab5-4169-93f8-a5ae006f3e4e.sqlserver.sequelizer.com;Database=8a5ae006f3e4e;User ID=namucclqps;Password=54nWBkCfURyMzYfhbu8NUQb6PEZUsWcoN;"" providerName="System.Data.EntityClient" />
</connectionStrings>
Update 2:
I installed SQL Server Management Studio. Then I hosted my website on appharbor and installed add-on SQL Server. Then using following info I connected to Server.
Then added tables in SQL Server Management Studio and changed connection string in web.config and published website.
LocalDB is only a thing inside Visual Studio. There's no way to even get it on a production server. You need to install some version of SQL Server and then create your database and tables there.
After that, leave the original connection string inside Web.config alone, and instead, add a transform in Web.Release.config that changes the connection string to the one for your production SQL Server instance of your database. Finally, when publishing your site, select the "Release" configuration. The Web.config will then be transformed during publishing and will reference the production database once the site is deployed.

ASP.NET MVC 3 app cannot connect to SQL server 2008 instance on AWS instance

When running an ASP.NET MVC 3 app (written in VS 2010, tested and working using SQL Server Express 2012, .NET 4.0, Windows 7 Pro) on an Amazon Web Services host (Windows Server 2008, ASP.NET 4.0 app pool, SQL Server Express 2008, IIS7), I am unable to connect to the local database on that machine, nor see any errors in connecting. I am using the following ConnectionString in Web.config:
name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=aspnet-NewWebSite-20141030101548;Integrated Security=SSPI" providerName="System.Data.SqlClient"
Is there a modification I should make to this to make it work? I can't upgrade to SQL Server 2012 on this AWS instance. I can't even log to the Event Viewer or email errors to myself. I'm stumped.
Your connection string is pointing to a local db instance, and AWS probably doesn't support LocalDB. What you want to do is to get a DB instance that supports remote connection ( you can get one from AWS directly) and find out the connection string of that server, change yours accordingly.

Windows application and SQL Server 2000 database on client machine

I have installed a .net Windows application on a client's machine and its database is in SQL Server 2000.
For the application, I installed the .net framework and other support software and for database I installed SQL Server 2000 and created a database over there and connect it. Working properly
But now client changed from Windows XP to Windows 7. I search for installation of SQL Server 2000, but it's not working over there. So what I did, I sent the .mdf file of the database with exe application and make connection string
<add name="AccountingConnectionString"
connectionString="data source=.\SQLEXPRESS Integrated Security=SSPI;AttachDBFilename=C:\SetupOfApplication\DataBase\Database.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
and it's also working.
Now i change something in database, and trying to update the .mdf file but its not reflecting the new one .mdf is getting the old one. I am stuck......
Did I do something wrong? Because its difficult for me to fix.
OR
I want to know what is the efficient way of use of SQL Server 2000 database on Windows 7 or any else solution is there?

Categories

Resources