How to connect the oracle database with .net? - c#

How to connect the oracle database as a backend in asp.net (C#)?
what is the connection string for it?
when i was trying to connect i got the below error:
ORA-12154: TNS:could not resolve the connect identifier specified

The actual connection string depends on the parameters of your server (ip, instance name, credentials, etc).
Here's a site with several 'example' connection strings for oracle:
http://www.connectionstrings.com/oracle

To connect to Oracle DB with .NET, best way is:
Install Oracle client
Configure tnsNames.ora
Reference .net project to Oracle.DataAccess.Dll (ODP.NET)
Create connection using OracleConnection object
I will not even go into other possibilities because this is golden standard for .net-Ora connectivity

Related

How do I connect to my Google cloud SQL instance with C#?

I am trying to use visual studio to write a program in c# and have it connect to my google cloud sql server. Unfortunately I have been trying to troubleshoot it and have had no luck. I already added my IP and my connection works through MYSQL Workbench.
I attempted to connect with the whole data source, network library, initial catalog, etc. I tried it without the network library and used the proper way to escape \ in the string during the connection. I also tried the default 1433 port and 3306. No luck.
// Build Connection String
SqlConnection clearviscon = new SqlConnection(#"Server=xx.xx.xx.xx\alpine-park-243102:us-central1:xxx, 3306;Network Library=DBMSSOCN;Initial Catalog=xxdatabase;User ID=root;Password=xxx123");
clearviscon.Open();
To connect to Google Cloud SQL for MySQL, you must use a MySQL client library. I recommend MySqlConnector.
Your connection string will be Server=xx.xx.xx.xx;Database=xxdatabase;User ID=root;Password=xxx123.
If you're using a client SSL certificate to connect to your server, add this to the end of your connection string: ;SslCa=server-ca.pem;SslCert=client-cert.pem;SslKey=client-key.pem.
You must use MySqlConnection.
See this link for more information: https://cloud.google.com/dotnet/docs/getting-started/using-cloud-sql

How connect C# to Postgresql in host j.layershift.co.uk

I have installed postgresql database in http://postgres-project-1241043.j.layershift.co.uk/ host.
I want to connect to the database using C#. I use Npgsql with following connection string.
connectionString = # "Server = postgres-project-1241043.j.layershift.co.uk, Port = 5432, User Id = postgre; Password = abcdef; Database = dbluanvantn;";
But I am not able to connect to the server and get error:
Npgsql.NpgsqlException: Failed to a connection to
'postgres-project1241043.j.layershift.co.uk'.
Am I using correct connection string?. Help me fix it.
You can only connect to Postgres (on our Jelastic service) if you add a public IP to the node first. Without that step, you can only connect to it locally (i.e. from another server within your Jelastic environment).
Also I want to mention that you are always welcome to contact our support team (our tech. support is 24x7 and completely free; even for our trial accounts) if you need any further help.

Visual C# 2010: Unable to connect to XAMPP localhost

I am unable to connect to XAMPP localhost in my C# Windows form application.
My code is:
SqlConnection connection = null;
try
{
connection = new SqlConnection("user id=root;" +
"password=12345678;" + "server=localhost");
connection.Open();
}
catch (Exception exptn)
{
MessageBox.Show(exptn.ToString());
}
I made sure to include "using System.Data.SqlClient;" so that my code runs. The timeout error I get at runtime is:
"System.Data.SqlClient.SqlException (0x80131904): 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."
There was more to the error message, but it was uncopyable and too long to post here. I have tried to install MySql and the .NET MySql connector separately from XAMPP. I added MySql.Data as a reference in Solution Explorer (My research told me to add MySql.Data and MySql.Web, and MySql.Data was the only one listed in the options.). Another source told me to add a Microsoft ODBC Data Source in Server/Database explorer, but the option was not available in Database Explorer. I have made sure XAMPP is running and working properly in phpMyAdmin, and I am able to create tables and run queries there. Many sources also seem to have different opinions as to what is needed in the connection string.
I am completely at a loss as to how I am supposed to connect to localhost databases from another application on the same computer. Forgive me if I am overlooking something basic or if this is a noob question, but I know little about connecting to databases (this type of thing is precisely the reason why). Can anyone help me connect to XAMPP localhost from C#?
Install MySQL Connector from Oracle and then use class MySqlConnection.
Here is the download link -
http://www.mysql.com/products/connector/
Download the driver for ADO.Net and the documentation to use it is here -
http://dev.mysql.com/doc/connector-net/en/connector-net-introduction.html
SqlConnection is for MQ SQL server only and thus it is looking for a instance of MS SQL Server to connect to and it fails to connect since none exists. This explains the error message.

Could not connect to SQL Server but Excel and ODBC config can

I have a C# program to connect to SQL Server. It works fine at the test computer with SQL Server 2012 but does not work on the production environment with 2008. At the production environment, it reports exception as such,
Unhandled Exception: System.Data.SqlClient.SqlException: A network-related or in
stance-specific error occurred while establishing a connection to SQL Server. Th
e server was not found or was not accessible. Verify that the instance name is c
orrect and that SQL Server is configured to allow remote connections. (provider:
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) --
-> System.ComponentModel.Win32Exception: Access is denied
here is my connection code,
connStrSql = "Server=" + sqlserver + "; Database=" + sqldb + "; Trusted_Connection=True";
SqlConnection sqlConn = new SqlConnection(connStrSql)
sqlConn.Open();
The target platform is x86 and target framework is 4.5. The funny thing is that Excel and ODBC config can connect to the database without complain. Does C# program use different way connecting to SQL Server? How can I fix the problem?
There are many possible reasons why you can not connect to an SQL Server database. This is a great trouble shooting guide to help you solve the above error.
Briefly:
Is the SQL Server services running?
Has the SQL Server TCP/IP settings been configured?
Does the firewall settings allow SQL Server through?
Has SQL Server itself been configured allow remote connections?
Other things to consider
Is the value of sqlserver correct?
Has the client protocol you are using to connection to SQL Server, such as Named Pipes, been enabled?
One of the most common reasons for a remote connection being refused in newer versions of SQL Server is the SQL Browser is not turned on. It is off by default after an install. Another common reason is you don't have the particular protocol (in this case net pipes) turned on, but I would check the SQL Browser first, as it is probably turned off.
Might be firewall/security restriction in production - Try running against a local SQL2008 db because I just ran the code against SQL2008 and it does work with a correct sqlserver and sqldb parameter and change the line below ( missing ; )
SqlConnection sqlConn = new SqlConnection(connStrSql);
Try this for SQL Server connection:
Attach a database file on connect to a local SQL Server Express instance
Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname;
Trusted_Connection=Yes;
Attach a database file, located in the data directory, on connect to a local SQL Server Express instance
Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;
Trusted_Connection=Yes;
Try this Excel Connection string
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1";
If any other problem regarding connection string, refer this site
MS-Excel: http://www.connectionstrings.com/excel/
MS SQL Server: http://www.connectionstrings.com/sql-server/
Thanks,
NB

connect mysql with c#

I'm building a c# windows application which will connect with the mysql database in a remote server.
I'm using the following connect script
string connectionString;
connectionString = "SERVER = eu5.org;UID = myuserid; PASSWORD = mypassword; DATABASE = mydatabasename;";
connection = new MySqlConnection(connectionString);
It shows the error couldn't connect to the database.
P.S: Mysql database is at eu5.org server
Personally I prefer to use the MySql Workbench IDE for testing connections and working (Querying) the database directly where possible. Most hosted databases that I have worked with normally define the Server as Instance.[DomainName] so I would have expected your server URL to be something like MySql1.eu5.org
Below is a connection string that I tested using the MySql Connector, change the parameters.
<connectionStrings>
<add name="MySqlConnection" connectionString="server=INSTANCENAME.DOMAINNAME.COM;UID=USERNAME;password=PASSWORD;database=DATABASENAME;Persist Security Info=True;" providerName="MySql.Data.MySqlClient"/>
MAke sure that your server should be started...
Just read the FAQ:
Many people want to only use database, but their site is hosted elsewhere. We provide free database for websites hosted with us. For that reason, external access is blocked without exception.
--> http://www.freewebhostingarea.com/faq.html
so it's not possible to access your MySQL-DB from external sources.
only localhost will be allowed
Your code is correct.
Use a browser for MySQL, like http://mysql-query-browser-for-windows.apponic.com/ to check if your database is available.

Categories