I am trying to connect to an oracle database from my website (asp.net-mvc). The only information i have to connect to the database is ODBC instructions which tells me to go:
It says to go into an oracle directory on the machine and enter this into a TSNNames.ora
file and enter this in:
DBNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=[machine])(port=[port]))
(CONNECT_DATA=(SID=[DBNAME])))
and then go to control panel and manually add a connection through the GUI wizard.
Is there anyway i can connect to this database without have to set this up? I was hoping to simply stick a connection string in and be on my way. I deploy to different machines and i dont want the burden of having to update the .ora files or walk through this GUI wizard setup.
Does anyone have a suggestion for me?
In the Oracle ODBC Driver Connect window the Service Name and User ID fields are prefilled with the information you supplied in the Oracle ODBC Driver Configuration window. Enter the password for your user ID and click OK. You are notified that the connection was created successfully. Click OK.
Start the ODBC test utility by selecting Start > Programs > Oracle > Network Administration > Oracle ODBC Test or by searching your system for the file ODBCTST. EXE and double clicking on the file. Click on the CONNECT button displayed by the ODBC Test utility.
Don't use ODBC. ODP.NET is a driver provided by Oracle which is based on the same model as SQL Server: simply download the assembly, reference it in your project and use it:
using (var conn = new OracleConnection("Some connection string"))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT id FROM foo";
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int id = reader.GetInt32(0);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With