Can't connect C# application to Oracle 11g - c#

I have 2 stumbling problem:
1) Which is the correct port number?
This is the link when I run my Oracle 11g:
http://127.0.0.1:8080/apex/f?p=4950:1:786646867589622
I'm confused as to my port number is 1521, 8080 or 4950?
2) ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
This is my connection string:
string oradb = "Data Source=(DESCRIPTION="
+ "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + server + ")(PORT=" + port + ")))"
+ "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));"
+ "User Id=" + uid + ";Password=" + password + ";";
And my connection parameters are:
DB obj2 = new Oracle("localhost", "1521", "system", "dada050909");
Am unable to connect and was displayed the error 12514.
Please help - I'm not very familiar with C# and Oracle. Have been stuck for quite some time.

Related

ERROR: Unable to connect to any of the specified MySQL hosts - Synology NAS - MariaDB 10 - C#

I have a problem to connect my C# application in Visual Studio 2019 to Database inside Snyology NAS using MariaDB 10. If I connected the Database with HeidiSQL works good, but if I try to connect C# App with the same credentials I see an error like this:
"Unable to connect to any of the specified MySQL hosts"
I tried to check and I verified that:
TCP functionality is enable on Synology NAS
User and password are correct and I have all the privileges
Database name is correct
Port is also correct 3307 (setting default on Synology)
This is the code that I use to check the connection:
string connectionString = "";
string server = "ip_address_NAS:3307";
string database = "my_Database";
string username = "my_user";
string password = "my_password";
MySql.Data.MySqlClient.MySqlConnection cn;
connectionString = "SERVER=" + server + ";DATABASE=" + database + ";UID=" + username + ";PASSWORD=" + password;
try
{
cn = new MySql.Data.MySqlClient.MySqlConnection(connectionString);
cn.Open();
label1.Text = "Database ONLINE!";
label1.ForeColor = System.Drawing.Color.Green;
cn.Close();
}
catch(Exception ex)
{
label1.Text = "Database OFFLINE!\n" + ex.Message;
label1.ForeColor = System.Drawing.Color.Red;
}
Why this error?
Can you help me? please.
Thank you.
Remove the port number from the hostname. If you are connecting to the default port, there's no need to specify a port. If you are connecting to a custom port, it has to be defined in the following way
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPassword
Docs
Edit
3307 is not the default port for MySQL or MariaDB. So if your database is running on port 3307 (because for whatever reason Synology has chosen it to be the initial setting) you need to specify that port in the connection string. But not as part of the servername but with the Port=3307 property.

Access denied for user 'root'#'%' (using password: YES) but logged in as root

I'm aware there are similar questions all over the web, but I can't find anything for this particular issue. I have C# experience, but am pretty new to MySQL, so perhaps there's something I'm not understanding. I'm trying to make a simple select in C# from a MySQL table:
string server = "192.168.2.6";
string database = "productintegration";
string uid = "root";
string password = "Password1";
string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
MySqlConnection connection = new MySqlConnection(connectionString);
string query = "select * from tcdidataimport";
connection.Open();
MySqlCommand cmd = new MySqlCommand(query, connection);
MySqlDataReader dataReader = cmd.ExecuteReader();
DataTable dt = new DataTable();
if (dataReader.HasRows)
{
dt.Load(dataReader);
}
connection.Close();
And I get the following exception:
Authentication to host '192.168.2.6' for user 'root' using method 'mysql_native_password' failed with message: Access denied for user 'root'#'JUSTINSPERSONAL' (using password: YES)
Seems simple enough... Except that I'm already connecting to that server (via MySQL Workbench) using that exact login.
Here is show grants;
Which seems to me that I should be able to log in using root at whatever I want? When I tried to create another user (CDISelector#'%') and grant privileges I got a similar error:
But I'm logged in as root? Am I missing something here? Finally, here's the results of select user(), current_user();
JUSTINSPERSONAL is my PC, 192.168.2.6 is the MySQL machine's IP. Not sure what I'm missing here but this all seems a little strange.
And it turns out I had the password incorrect. Ha.

Connection String for MySQL (C# in asp.net)

I am using a the C# ODBC object in asp.net to connect up to a MySQL server hosted on another computer (on the same network).
<%# Import Namespace="System.Data.Odbc" %>
<html>
<body>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
try
{
using(OdbcConnection connection = new OdbcConnection("DRIVER={MySQL ODBC 5.51.30 Driver};Database=test;Server=192.168.1.109;UID=Username;PWD=Password;"))
{
connection.Open();
using(OdbcCommand command = new OdbcCommand("SELECT * FROM tablename", connection))
using(OdbcDataReader dr = command.ExecuteReader())
{
while(dr.Read())
Response.Write(dr["name"].ToString() + "<br>");
dr.Close();
}
connection.Close();
}
}
catch(Exception ex)
{
Response.Write("An error occurred: " + ex.Message);
}
}
</script>
</body>
</html>
I am currently getting this error when I run the code:
An error occurred: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I am hosting this on a Microsoft IIS server, with ASP.net enabled. Would I be able to get any help with fixing this error?
Link to image of my MySQL server: http://i.stack.imgur.com/4NYCr.png
Would I be able to get any help with fixing this error?
Yes, you would. So, your only question was answered. And now? Please think a little more about WHAT you ask.
TO your problem.
Like always, http://www.connectionstrings.com/ is the primary resource for this ;) Anything you ever wanted to know about connectionstrings on one place.
For MySQL (asuming 5.2) you can find (for ODBC) the solution at:
http://www.connectionstrings.com/mysql-connector-odbc-5-2/
Now, your string looks good - so I start assuming you have a driver problem. I would assume that wherever you run it it just does not have - the ODBC ddriver installed.
THAT SAID: there is no real reason to use ODBC (which has native prerequisites) and not a (managed) MySQL Driver?
if you really miss the ODBC driver, you can ind the downloads at http://www.mysql.com/products/connector/. But I would really not use ODBC here - not with a native connector available.
I think you better use MySQlConnection as well as MyqlCommand for your needs:
eg:
server = "localhost";
database = "connectcsharptomysql";
uid = "username";
password = "password";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);

Where can I find MySQL Server name?

I am new to MySQL, I am setting up a database connection to be used for a C# application. I am following a youtube tutorial on setting up this connection, but I am confused on what is a Server name? Is it just the IP Address or do I have to include the company domain name whos providing the server. Would the following be correct?
private void Initialize()
{
server = "xxx.1x4.xxx.15x";
database = "nameOfDatabase";
uid = "username123";
password = "pass123";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
}
Using the ip adress along with the actual port for the mysql service will work unless security measures have been taken to prevent access.
example : 127.0.0.1:1840
In short, yes, you can use the IP address, although I've always used the hostname.
You might want to check out this question:
Accessing SQL Server using an IP Address and Port Number ... Help!

How do I access an Access database protected by a username/password in Access workgroups via Jet?

I found this page which suggested adding the "Jet OLEDB:System Database" item to my connection string, and then providing a username and password parameter to Open. Unfortuanately, it seems the .NET OleDb classes don't seem to have this... I tried the following code just incase:
testConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbFile +
";Jet OLEDB:System Database=" + Path.GetDirectoryName(mdbFile) + "\\system.mdw;" +
"Jet OLEDB:System Username=***;Jet OLEDB:System Password=***");
But this just seems to hang for a long time before throwing a "Could not find installable ISAM" DbException.
Does anyone have any ideas?
EDIT: I tried using the following connection string, which stopped the exception, but didn't let me access any tables, like what happens when I open Access without the workgroup setup properly.
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbFile +
";Jet OLEDB:System Database=" + Path.GetDirectoryName(mdbFile) + "\\system.mdw;" +
"User ID=***;Password=***";
I feel like an idiot now, but scrolling up a bit on that page accidentally, I noticed some of the connection strings had a "User ID" and "Password" parameters. Changing the connection string to use these instead of trying to pass them to "Jet OLEDB:*" fixed the issue.
ie, my final connection string was:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbFile +
";Jet OLEDB:System Database=" + Path.GetDirectoryName(mdbFile) + "\\system.mdw;" +
"User ID=***;Password=***";

Categories

Resources