I'm developing desktop application with MS Visual Studio 2008 c# and i'm trying to connect to mysql database. I download connectors, added references and i have this code:
try
{
MySqlConnection conn = new MySqlConnection("server=127.0.0.1;User Id=user;Pwd=pass;database=db");
conn.Open();
}
catch (MySqlException exp)
{
Console.WriteLine(exp.Message);
}
On conn.Open(); i got MySqlException Unable to connect to any of the specified MySQL hosts. The worst part is that i can connect to database throw Server Explorer in MSVStudio.
I reviewed all similar questions, but I didn't get answer!
Pls help!
I realize this question is a couple of years old but I was having the same problem in VS2015 Community Edition when trying to open the Query Builder in the DataSet Designer. I searched all over the web trying to find a fix and none of them worked. Finally I found the answer by accident.
What is happening is VS doesn't realize that it has to open a connection first, the error message is very misleading. To remedy the problem all you need to do is in the Server Explorer under the Data Connections find the connection that you are working on and simply double click on it to open. That's it!
If you look at the Icon next to the Connection you will notice that it changes from to showing that the connection is open.
Related
Im developed a software and it's now time to test it connection to a online server.
Im developing in C# using Visual Studio and I'm trying to connect to a MySQL server. To be specifc Im trying to connect to a test server at db4free server.
I changed my ConnectionString to:
connectionString = "SERVER=db4free.net;PORT=3306;DATABASE=prpsystem;UID=database;PWD=password;";
But when I try to open the connection to check if the login is OK the visual studio shows this message error:
Guid should contain 32 digits with 4 dashes.
Do you guys know what is happening? Thanks for the help.
Your crash is coming from Driver.LoadCharacterSets, which is executing SHOW COLLATION. This is bug 92982 that has been reported against the Connector/NET driver.
According to the OP on that case, he fixed the problem by disabling the skip-character-set-client-handshake setting in his my.cnf for MySQL Server. If you also have that setting, try disabling it to see if it resolves the problem.
Otherwise, you could switch to MySqlConnector, an alternate ADO.NET library for MySQL, which doesn't have this bug.
As shown in pictures, "ProjectDB.db" is a database I built through the SQLite Compact Toolbox. The database indeed exists in that folder path. The exception as in the title is thrown as I debug the app.
UWP App. Visual Studio 2017. Windows 10.
Snapshot of Errors while running application
enter image description here
enter image description here
Connection string for connecting SQL lite Database
SQLiteConnection db =
new SQLiteConnection(#"Data Source=C:\Users\georg\source\repos\DatabasePractice\ProjectDB.db;Version=3;";
db.Open();
Sqlite on Windows a directory/path should use a double backslash like this:
C:\\Users\\georg\\source
If this does not solve your problem, attempt these troubleshooting steps:
Is the Database stored on a remote server or 'read-only' directory?
Is the parent directory a 'read-only' directory?
Try executing your code with the Source="...Practice\ProjectDB;" not "\ProjectDB.db;"
Is something else attempting to read the database? Although this should throw a 'database locked' exception which makes this one unlikely.
I was facing same issue on the shared hosting server, My C# code was able to read data from SQLIte db file. But while add / update data it was throwing Error "unable to open database"
I tried many options suggested on stackoverflow But after referring https://stackoverflow.com/a/17780808/2021073 and
https://www.sqlite.org/pragma.html#pragma_journal_mode I tried adding journal mode=Off; to the Connection string
and it worked for me
sample code
SQLiteConnection connection = new SQLiteConnection("Data Source=G:\dbfolder\sqlite3.db;Version=3;Mode=ReadWrite;journal mode=Off;", true);
Within my ASP.NET C# WebForms app I am attempting to connect to my SQL Database.
Upon connection I get the error:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I've attempted to google what this error means but the results do not clearly explain whats wrong. Can you tell me what exactly is wrong (its not finding the database file, it found the file but the database file is incorrect version, etc.)?
These are the steps I have performed:
Create a local database using VS2013. The file is located in 'MyProjectPath\App_Data\Pages.mdf'
The database is populated with a table and rows
I have connected to the server by 'Server Explorer->Connect To Server->Type in my computer username'. No errors appear
In the Server Explorer I have tested my connection to the database and it succeeded.
Connection is 'Microsoft SQL Server Database File (SqlClient)'
I have copied the 'ConnectionString' to web.config. One important thing is that the string contains quotation marks and I have to remove these.
Do I need to start an external application like SQL Server Management Studio or something?
Connection String:
Data Source=(LocalDB)\v11.0;AttachDbFilename="C:\VERY_LONG_PATH_THAT_HAS_SPACES\App_Data\Pages.mdf";Integrated Security=True
I remove the quotations:
<connectionStrings>
<add name="MySQLConnStr" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\VERY_LONG_PATH_THAT_HAS_SPACES\App_Data\Pages.mdf;Integrated Security=True"/>
</connectionStrings>
// My simple connection code where the runtime error occurs
try
{
using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString))
{
// do stuff
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Hi to make ODBC connection you need to have driver installed. You can make sql connection and this should work..
// Change your simple connection code to
try
{
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString);
connection.open();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Try one by one below three solutions, it will help you to solve your problem.
You need to configure DSN in Administration Tools => ODBC, When install driver choose for all users instead current user
Try to look on your server for the ODBC Data Source Administrator that can be found in Control Panel --> Administrative Tools --> Data Sources (ODBC). (On 64 bit Windows systems, you'll have to explicitly call c:\windows\syswow64\odbcad32.exe ) and add the driver to the System DSN tab.
If the ODBC driver was not 64 bit, Try to compile your application as an x86 process and it will work.
I am new to mvc and entity framework I was following this tutorial to create an application with code first approach, the problem is program runs perfectly but i cannot see tables created in localdb, I am getting this error (Invalid column name 'is_memory_optimized') whenever I try to open tables from server explorer connection, in any connection.
I have visual studio 2013 and sql server 2014, i guess the problem is about sql server 2014 because in msdn website they say that "Something is not what it should be. 'is_memory_optimized' relates to a new feature in SQL 2014. I can't say what happned, but I would suggest that you install service pack 2 of SQL 2012 which was released recently. With a little luck it repairs the error." in msdn forums but none of the comments solved the problem i also checked this post in stackoverflow but that didn't work either.
This is exactly what i receive as error:
This is not exactly the solution of the problem because i am still getting the same error in server explorer, but you can view the table diagram in server object explorer instead.
Also you can view it in SSMS by connecting to (localdb)\MSSQLLocalDB, which is default connection in appconfig or webconfig, or you can change the connection to (localdb)\v11 or (localdb)\ProjectsV12 and again view it either in Server Object Explorer or SSMS. You can see the list of local dbs in command prompt by "sqllocaldb info" command.
I also found these links pretty useful related to this topic and db connections in code first approach:
http://blogs.msdn.com/b/davidobando/archive/2012/08/14/changing-ef-s-default-provider-from-localdb-to-sql-server.aspx
How to connect to local instance of SQL Server 2008 Express
http://msdn.microsoft.com/en-us/data/jj556606.aspx
Code-First change data source without connection string
Hi I have to connect to an Oracle Database( about which I know a little) using a windows application.
The windows application will not necessarily be in the same system.
I just needed the connection string.
So I Used Add connection functionality in Visual Studio 2014 to test the connection and get the string.
eedb is the SID which i read in stackoverflow question
Now using above, i was able to connect to the database using this functionality and even in my visual studio server explorer all the tables of the oracle database were showing but I needed to use the connection string in the windows application.
So I used following string:
DATA SOURCE=172.31.8.21:1521/eedb;USER ID=PDB_E_GND_R
I added password too to this string as
DATA SOURCE=172.31.8.21:1521/eedb;USER ID=PDB_E_GND_R;PASSWORD=123
when i run the application i get error.
System.Data.OracleClient.OracleException: ORA-01017: invalid username/password; logon denied.
So :
Why I am getting this error. Now some may mark this question as duplicate and even point out the answer can be found in issue stackoverflow question
Coz if this was the case I would have been unable to establish connection through add connection functionality of Visual Studio at all.
Please note: I added the reference: Oracle.DataAccess
And also for a programmer like me who has very little knowledge regarding the oracle.
How I can know which connection string I have to use for a particular oracle db.
Try the following connection string EZ connect does not seem to be so EZ
data source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 172.31.8.21)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = eedb)));USER ID=PDB_E_GND_R;PASSWORD=123