Connection error when configuring MySQL data source in Configure Data Source wizard - c#

I'm currently using VS2015 and a local instance of MySQL Server (managed through Workbench) to develop a school project.
The project is a Web form app (.NET/C#) which I have never really done before. I have done C# with a MySQL connection in the past but I think it was just a Windows form app, and I had no issues connecting the database to the form.
I'm currently trying to use a GridView element from the toolbox in Visual Studio to connect to my database. When I go in and edit the source settings, I can create a connection and it will see the tables in my database.
I can then click the "Test Connection" button and it will succeed in connecting. However, if I go forward and try to select items to view from the table, and then click "Test Query" I get the following error:
I have Googled the error and tried some of the solutions found on SO like installing the Clear MEF Cache extension, but it didn't solve anything.
Additionally, I've created some functions from scratch to connect and insert data. They also have problems in that trying to insert any more than one value into the table will fail. Like INSERT INTO user_info(user_id, user_name) VALUES ('5', "Bob") will insert the user_id but not the user_name.

Please see here for a tutorial to connect to MySQL and here for filling your DataGridView from MySQL. Make sure you have the correct reference added to your project as well (References > MySQL.Data).

Related

Could not create database using package manager console in .NET 7.0

Im learning .net now and following along the course,my goal is to create CRUD app so i need a database to work with it, i have succesfuly created initial migration but database-update doesnot work
(provider: SNI_PN11, error: 50 - Local Database Runtime error
occurred. Cannot create an automatic instance. See the Windows
Application event log for error details.
im getting this error if connection strings look like this
"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
i have installed both sql server and sql management on windows 11 without problem
and if i change connection string to this
"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
deleting \ problem now is
Unable to create an object of type 'QuotesAppContext'.
so it seems like an endless circle to me, thanks you for your help
write database-update and get database instance working
I find the answer which have worked for me,find this folder in regedit
"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SQL Server\UserInstances"
and delete everything inside of it,and after that run Update-Database command again everything should work fine
P.S
i have tried reinstalling sql server,adding ports, but this solution worked for me

Working with Sample Databases

I have been working with SQL-Server for awhile as part of my weekly routine, and since everything was setup in advance, I take everything for granted.
Start SQL Server, pick a Server name, pick SQL Server Authentication, then type my login and password
or from an application just use a given connection string and everything works like charm
Until all the sudden, a third party sent me an application sample that needs to be reviewed, and it includes a Northwind database, and from that point on I am having difficulty getting this sample to work.
Changing the connection name and pass to match SQL Server instance credential does not solve the problem
This is how my string usually looks like
I have SQL Server 2014 installed and also this is how the application folder structured
In Server Explorer in Visual Studio the connection is recognized and when I attempt to access, I get
How to think about this problem in order to solve it and get the sample running? There is a missing gap that I cannot point my finger to.
I have two solutions for you.
In Visual Studio, create a class library project. Delete the default class file. Right click the project name -> Add -> New item -> Select "ADO.NET Entity Data Model" name it what you want and click Add. Make sure "EF Designer from database" is selected and click Next. Click New Connection. Next to "Data Source" click Change. Select "Microsoft SQL Server Database File", click OK. Click Browse and select the .mdf file for the database. Select "Use SQL Server Authentication" and provide your login credentials, then click Test Connection. If the connection fails, your login is wrong (minus a random super rare occurrence). Click OK and finish out the menus. Go into the App.Config and copy the entire xml tag. Go into your application project, right click, the project name -> Manage NuGet Packages -> Browse -> Search for EntityFramework, select it and click Add on the right hand side. Accept the terms it provides. Go into your application projects App.Config and paste the xml tag you copied into the xml tag. To use it, copy the value of the name attribute from the tag from earlier and do the following
using (var db = new NameAttributeFromAddTag())
{
// Use standard link notation
var item = db.TableName.Where(i => i.Id == idYouWant);
}
(You can find more info about adding the connection here: https://msdn.microsoft.com/en-us/library/jj206878(v=vs.113).aspx)
Open up SQL Server Management Studio and connect wherever you want to (Such as computerName/SQLExpress (your default local DB server)). Right click Databases -> Attach -> select .mdf file for the database. Click Ok, click Ok again. Connect to that database as you would any other database. If it still says your login is incorrect, In SQL Server Manager look at Databases -> yourDatabase -> Security -> Users and check the properties of the user you are trying to use.
This is precisely how I got it to work:
Install SQL Server Express edition (Not SSMS)
Open SQL Server Management Studio (SSMS) and enter parameters as seen
Attach Database mdf file
In the application Config file add a connection string similar to
As a note:
.\sqlexpress Server name or Data Source in the connection string could be replaced with (local)\sqlexpress
I found this by chance while querying data in SSMS and looking at the bottom:
Also found this answer useful in explaining that dot, (local) and Computer name are all equivalents

Missing Server and User in Credentials

I'm currently working with VS'13 for making c# metro forms and mysql workbench for database. The problem occurring is that it shows the error of
Missing Server and User in Credentials.
Host 'WAJiHA' is not allowed to connect to this MySQL server
(as you can see in the picture as well).
DataAccess file has following settings
"Server=localhost;Database=sbhd_v13;Uid=root;password=test123";
The database is connected with the project and executes query but doesnot allows to access the connection to the current project or any other project.
It was working good last night idk which configurations i had edited by mistake which is causing such error.
Kindly help me! I'm unable to find the right solution for this problementer image description here
Change your posted connection string to be like
string myConnectionString = "server=127.0.0.1;uid=root;pwd=test123;database=sbhd_v13;";

How can I configure the MYSQL ODBC driver to work with Visual Studio 2013?

I've installed MYSQL server, running local on 127.0.0.1
(I've also tried this with MySQL server at a public IP with same results).
Here is how I'm configuring it:
Using MySQL Connector / ODBC (running localhost mysql server) using Visual Studio 2013 C#
I click Design tab of a webform.aspx page - and click and drag (from Toolbox->Data->GridView into the MainContent frame, and drop.
I then click the [>] button
Under Choose Data Source, I choose to create a new data source.
Under Data Source Configuration Wizard, I choose SQL Database.
Next pops up a window, Configure Data Source - SqlDataSource1
I click New Connection
Microsoft ODBC Data Source (ODBC) is selected as Data source - I leave it (note: here, I have tried changing this to MySql Data Source - but the connection fails). so I use the ODBC option.
I click the () Use Connection string: and click [Build]
A window pops up, and I select the Machine Data Source tab
I have already created a Data Source named test_localhost_mysql, I select it.
A window with MySQL Connector/ODBC connection parameters appears, with all of my connection data. I click Test.
success.
I click [OK]
Now, the Add Connection - Use connection string, is filled in, along with my login information.
I click Test Connection
Success.
I click [OK]
configuration wizard is now complete, and shows a string.
I click [NEXT]
I click [NEXT] without changing anything
Now is when it becomes interesting. on this screen;
under Specify columns from a table or view - all my tables are in the drop down list. Periodically, the columns will show here as well. Currently they aren't -- I'm sure this is not random, although I'm not sure what I'm doing to cause it.
I click [Next] after selecting my table.
I click [TEST]
It fails.
I am sure it's something simple, but I promise I've been through everything I can think of, and can really use some help please.
Anyone that can guide me I would greatly appreciate it.
I anxiously await your genious :) Thank you!
Check this out. Try to install with the instructions here. Report back if the issue persists.
http://www.w3resource.com/mysql/mysql-odbc-connection.php
EDIT: You also might want to run through all of your SQL code. It clearly says that the SQL syntax is not correct.

Getting Error while creating report through Report wizard. And Sql Database is on Godaddy's server

I am Using SQL Server Management 2012. And connected to my online database which is on Godaddy's server. I Create an windows application in c# and using visual studio 2012.
Used string constring = "Data Source=184.168.47.21;Initial Catalog=ROT;User Id=myusername;Password=mypassword;";
It works fine. Insert,update,delete all works fine.
But now i am creating report. For that i used Report Wizard -> New database ->new dataset -> New Connection -> Servername=184.168.47.21 , clicked on Use SQL server authentication , write Username, password, write or select database name = ROT , clicked on test connection and got message Test connection Succeeded.
In Short I create two files Named "Report1.rdlc" and "ROTDataSet.xsd".
I designed report completely and take a reportViewer1 for displaying Report1.rdlc.
** this.tbl_BookingTableAdapter.Fill(this.ROTDataSet.tbl_Booking,i);
this.reportViewer1.RefreshReport();**
above code is of button1_click event.And "i" is a integer parameter i am passing to it.
but when i click on this button it gives an error in file named "ROTDataSet.Designer.cs"
on line "this.Adapter.Fill(dataTable);"
Error says "SqlException was unhandled. Login failed for user 'myusername'."
Now Please tell me what i am doing wrong?
SqlConnection conn is working perfectly in application for select and insert query but it gives error in creating report. Even i can see my Table,Table adapter in .Xsd file.
go daddy doesnt support SSRS on shared hosting http://support.godaddy.com/help/article/6490/do-you-restrict-any-features-in-ms-sql-2008?isc=webxpa

Categories

Resources