.NET C#: Deploy Application Without Oracle Client Installed
By admin on Jun 20, 2011 in .NET, Oracle
You can deploy your database application using Oracle without installing the Oracle client.
What you will need is
- The following libraries from ODP.NET – http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
- OraOps11w.dll
- Oracle.DataAccess.dll
- The following libraries from Instant Client (either one). Basic Lite should do for most of the cases. (http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
- Basic – oci.dll, orannzsbb11.dll, and oraociei11.dll
- Basic Lite – oci.dll, orannzsbb11.dll, and oraociicus11.dll
Make sure all these libraries are in your deployment folder.
In your code, you have to make a reference to Oracle.DataAccess.dll, and use OracleConnection class directly.
Make a reference to Oracle.DataAccess.Client
1: using Oracle.DataAccess.Client;
Build up the connection string
1:
2: private string GetConnectionString()
3: {
4: // this connection string must be in a config file
5: return
6: "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server1.com)(PORT=1521))(ADDRESS = (PROTOCOL = TCP)(HOST = server2.com)(PORT = 1521))" +
7: "(CONNECT_DATA=(SERVICE_NAME=MyService)));User Id=myuser;Password=mypassword;";
8:
9:
10: }
Access the table using OracleConnection
1: string constr = GetConnectionString();
2:
3: OracleConnection conn = new OracleConnection(constr);
4: conn.Open();
5:
6: textBox1.AppendText(string.Format("State: {0}\r\n", conn.State));
7: textBox1.AppendText(string.Format("ConnectionString: {0}\r\n",
8: conn.ConnectionString));
9: OracleCommand cmd = new OracleCommand("SELECT * FROM MYTABLE", conn);
10:
11: OracleDataReader reader = cmd.ExecuteReader();
12: while (reader.Read())
13: {
14: string myField = (string)reader["MYFIELDNAME"];
15: textBox1.AppendText(myField + "\r\n");
16: }
Do not use the DbProviderFactories, it will throw an exception
1: string ProviderName = "Oracle.DataAccess.Client";
2: DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName);
Sorry, comments for this entry are closed at this time.