I have a console application to connect and update a record on oracle. This works fine. But after copying the same function onto an azure function, I am getting Connection Timeout issue. Does anybody know if there are some set ups or other configuration required on Azure?
Below is my code block:
OracleConnection con = new OracleConnection();
OracleConnectionStringBuilder ocsb = new OracleConnectionStringBuilder();
ocsb.Password = "xxxxx";
ocsb.UserID = "xxxxx";
ocsb.DataSource = "xxxxxxx";
con.ConnectionString = ocsb.ConnectionString;
con.Open();
OracleCommand cmd = con.CreateCommand();
cmd.CommandText = "UPDATE PRODUCTS SET STATUS = 20 WHERE STATUS = '30'";
cmd.CommandTimeout = 100000;
cmd.ExecuteNonQuery();
con.Close();
Partially answer for connecting to on-premise service like Oracle-db from Azure Functions, there is an existing SO thread had answered it, which you can refer to.
So first, you must make sure networking access to on-premise server available. Following this article about using Hybrid Connections.
Then, if you want to query oracle database via odbc, the oracle odbc driver must be installed on the client-side.
THanks for your help above,
The issue occurred because I made an update on the oracle console but did not commit. Unlike sql server, when you run an update statement, you should also run the 'commit' line of code.
Related
I'm trying to set up a local database (Service-based Database) in my C# app. When I intially adds the database to the project, I can see it and edit tables in both VS and SSMS, but when I try to connect to it programmatically, I get this error:
"Cannot open database \"[DataDirectory]DATABASE.MDF\" requested by the login. The login failed.\r\nLogin failed for user 'DESKTOP-MM6AR72\\majbom'."
And after that, the database is gone from both VS and SSMS.
I'm connecting this way:
using(SqlConnection conn = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=[DataDirectory]DATABASE.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"))
{
using(SqlCommand cmd = new SqlCommand(SQL, conn))
{
cmd.Connection.Open();
}
}
I have never tried to use databases this way, so maybe I'm doing something wrong. What I'm trying to accomplish, is a way of storing a lot af data temporarily in my app and make it searchable and editable.
EDIT:
I've followed this guide: https://learn.microsoft.com/en-us/visualstudio/data-tools/create-a-sql-database-by-using-a-designer
Thanks in advance
Is there any way to connect to Oracle DB without installing oracle client or using tnsname ? The application needs to be deployed on client machine ,hence want it to be INDEPENDENT.
To clarify on my comment, this is possible with the Managed ODP.net from Oracle, which does not require the client machine to have any Oracle clients/drivers installed. It's perfect for Windows or console applications where you can't control the software that's installed on the target machines.
To download the managed client, you can get it from nuget using the Library Package Manager (https://www.nuget.org/packages/odp.net.managed/):
PM> Install-Package odp.net.managed
With regards to TNSnames (since that is also a client dependency), if you use Oracle's EZ Connect, you can bypass TNSnames completely. To do this, you simply format your data source as server-name:port/sid. I actually stopped using TNSnames completely ever since this became available.
Here is an example of how you can do this with Managed ODP.net:
OracleConnectionStringBuilder sb = new OracleConnectionStringBuilder();
sb.DataSource = "MyOracle.MyCompany.com:1521/MySid"; // EZ Connect -- no TNS Names!
sb.UserID = "luke";
sb.Password = "Jedi4Eva";
OracleConnection conn = new OracleConnection(sb.ToString());
conn.Open();
OracleCommand cmd = new OracleCommand("select * from dual", conn);
object o = cmd.ExecuteScalar();
conn.Close();
I am trying to migrate my service cross-platform with mono, but in attempting to connect to a SQL Server database I get the following timeout error
Timeout expired. The timeout period elapsed prior to the completion of the operation or the server is not responding. at Mono.Data.Tds.Protocol.TdsComm..ctor
at System.Data.SqlClient.SqlConnection.Open()
Databases are fairly new to me, but as far as I can tell from here (Google cache page, mono site is down) accessing SQL Server databases is now possible in Mono. Is that correct?
I attempted to structure my connection string as shown, but still no luck. My simple test code...
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
SqlDataReader reader = null;
SqlCommand cmd = new SqlCommand("SELECT Parameter FROM Deltas", con);
reader = cmd.ExecuteReader();
reader.Read();
Console.WriteLine(reader["Parameter"].ToString());
con.Close();
}
Am I missing any references or is my format incorrect? How can I connect using Mono C#?
EDIT:
Connection String, Defined globally and init in constuctor:
cs = #"Server=xxx.xxx.xxx.xxx;
Database=myDB;
User ID=user;
Password=passwd;";
cs = #"Data Source=xxx.xxx.xxx.xxx;
Network Library=DBMSSOCN;
Initial Catalog=myDB;
User ID=user;
Password=passwd;";
Top is me trying to conform to the mono example, bottom is what works with the .NET runtime.
It seems you hit a bug:
http://www.mail-archive.com/mono-bugs#lists.ximian.com/msg50686.html
quote:
This only happens when using the .NET 2.0 version of TdsComm - when
compiling with .NET 1.0 (mcs instead of gmcs), the connection also
works.
Can I do this using SqlClient or do I have to use the ODBC route > ? I get error's in VS but from reading through the other post it appears to be an IDE specific problem.
The best way is to use ADO.NET which should work just fine. You should absolutely stay away from the ODBC route:
using (var conn = new SqlConnection("Data Source=mySql200Server;Initial Catalog=myDataBase;User Id=user;Password=secret;"))
using (var cmd = conn.CreateCommand())
{
conn.Open();
cmd.CommandText = "SELECT count(*) FROM foo";
var result = cmd.ExecuteScalar();
}
If this doesn't work here are the things to check:
Your connection string is correct (serverName/database/username/password)
You have access to the SQL server from within your ASP.NET server (verify network and firewall)
Your SQL query is correct
Use Microsoft Enterprise Library 5.0, specifically the Data Access application block.
http://msdn.microsoft.com/en-us/library/ff632023.aspx
http://www.codeproject.com/KB/architecture/MS-EntLib-DataAccess1.aspx
http://jwalin.wordpress.com/2009/02/11/get-started-with-the-enterprise-library-data-access-application-block/
Yes, you can use SqlClient, and you shouldn't get any errors.
I'm trying to search the Indexing Service of a remote Windows 2003 server from ASP.NET. There's sample code for this on the MS site, but only for local searches. Here's what I've got so far; the remote server in this example is called "indexserver", isn't on a domain, and has a index called "system":
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=MSIDXS;User ID=administrator;Password=Password";
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText= "SELECT * FROM indexserver.system..FILEINFO";
conn.Open();
cmd.ExecuteReader();
Running this gives me the error "Multiple-step OLE DB operation generated errors. Check the OLE DB status if available. No work was done".
Does anyone know how to get this working? All I need to do is query the Index for a filename and get the path of that file back.
Never mind, I discovered that Windows Indexing Service is somewhat depreciated,and Windows Search seems to be the way to go...