net: unknown error 1 - C# .Net 2.0 - oracle

Im getting error: net: unknown error 1
This is my code:
private void btnLogin_Click_1(object sender, EventArgs e)
{
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandTimeout = 0;
cmd.CommandText = "hhrcv_logon_validation";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("pv_emp_username", OracleDbType.VarChar).Value = txtUsername.Text;
cmd.Parameters.Add("pv_emp_password", OracleDbType.VarChar).Value = txtPassword.Text;
cmd.Parameters.Add(new OracleParameter("pv_return_message", OracleDbType.VarChar));
cmd.Parameters["pv_return_message"].Direction = ParameterDirection.Output;
string valid;
conn.Open();
**cmd.ExecuteNonQuery();**
valid = cmd.Parameters["pv_return_message"].Value.ToString();
if (valid.ToString() == "")
{
frmHome main = new frmHome(lblEmp_id_no.Text);
main.Show();
this.Hide();
}
else
{
MessageBox.Show("" + valid, "Error");
}
conn.Close();
}
Unhandled exception on cmd.ExecuteNonQuery();
Everything was working fine till today. First time that I'm getting this.
Its not really descriptive. Can someone please assist.

Our DBAs implemented password expiry dates on our user accounts. The one we were using for the app was expired. Although I could still use the account to make the connection to DB and actually query data in the DB it didn't want to work from the app.
So issue is solved.

Related

C# Core, OracleDataReader with hasRows as false while select all rows in a table that has data

I am testing Oracle database. I wrote some code but my datareader has no rows, why? My "carros" table has data and I am selecting all of them but I am getting an empty result set it seems.
string constr = "Data Source=localhost:1521/XE;User Id=System;Password=password;";
OracleConnection con = new OracleConnection(constr);
OracleCommand oracleCommand = new OracleCommand();
oracleCommand.Connection = con;
oracleCommand.CommandText = "select preco from carro";
con.Open();
OracleDataReader oracleDataReader = oracleCommand.ExecuteReader();
string resultado = String.Empty;
//My test, I got hasRows as false
if (oracleDataReader.HasRows == false)
{
resultado = "no results";
}
//never enters this loop.
while (oracleDataReader.Read())
{
resultado += (string)oracleDataReader["preco"];
}
// Close and Dispose OracleConnection
con.Close();
con.Dispose();
return resultado;
If HasRows is false after ExecuteReader, the problem is simply that the query is returning no rows so Read will return false as well. Perhaps the someValue variable is not set correctly.
From you description, it seems that your table is named carros while your query has used carro. Try to use
oracleCommand.CommandText = "select preco from carros";
A path towards solving this can include a scattering of logging commands that write to the file system.
System.IO.File.AppendAllText(#"\\server\\C\\log.txt", "put error message here" + "\r\n");
Or for printing a variable:
System.IO.File.AppendAllText(#"\\server\\C\\log.txt", ex.ToString() + "\r\n");
Pepper variations of this command throughout your script to see where failures are happening and to validate variable values.

Wrong number or types of arguments when calling a procedure in WCF service

I'm sort of having a hard time with this one. Well ok, I have two different solutions (solution1 has a WebApplication Project; solution2 has a Website Project). Inside the two solutions, there's a WCF service structure. I have the exact same code in both services (in their respective solutions). My code compiles just fine. From the service I do a simple call to a procedure that returns a cursor. When I execute the service from the WebApplication it works just fine; when I do the same from the Website I get error: "wrong number or types of arguments". They both call the same procedure, in the same DB. And I triple check my code, and is the same in both services. Any ideas or suggestions? My code is as follows in both solutions:
Service.cs
public List<A1001310> SearchClient_A1001310()
{
DataTable dataTable = new DataTable();
dataTable = DataManager.SearchClient();
List<A1001310> list = new List<A1001310>();
list = (from DataRow dr in dataTable.Rows
select new A1001310()
{
Id = Convert.ToInt32(dr["CLIENT_ID"]),
//ClientName = dr["NOM_CLIENTE"].ToString()
}).ToList();
return list;
}
DataManager.cs
public static DataTable SearchClient()
{
try
{
using (OleDbCommand cmd = new OleDbCommand(packetName + ".select_A1001310"))
{
cmd.CommandType = CommandType.StoredProcedure;
SqlManager sqlManager = new SqlManager();
return sqlManager.GetDataTable(cmd);
}
}
catch (Exception ex)
{
//TODO; Handle exception
}
return null;
}
The call to DataTable is:
public DataTable GetDataTable(OleDbCommand cmd)
{
using (DataSet ds = GetDataSet(cmd))
{
return ((ds != null && ds.Tables.Count > 0) ? ds.Tables[0] : null);
}
}
public DataSet GetDataSet(OleDbCommand cmd)
{
using (DataSet ds = new DataSet())
{
this.ConvertToNullBlankParameters(cmd);
using (OleDbConnection conn = new OleDbConnection(cmd.Connection == null ? _dbConnection : cmd.Connection.ConnectionString))
{
cmd.Connection = conn;
cmd.CommandTimeout = _connTimeout;
conn.Open();
//cmd.ExecuteScalar();
using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
da.Fill(ds);
}
return ds;
}
}
The procedure is as follow:
PROCEDURE select_A1001310(io_cursor OUT lcursor_data)
AS
BEGIN
OPEN io_cursor FOR
--
SELECT client_id
FROM a1001310
WHERE status = 'A'
--
EXCEPTION
WHEN OTHERS THEN
IF io_cursor%ISOPEN THEN
CLOSE io_cursor;
END IF;
--REVIRE: EXCEPTION HANDLER
END select_A1001310;
So if it helps anyone, I resolved my issue by specifying the OUT parameter declared in the procedure. This resulted in me changing from Oledb to OracleClient as follow:
public static DataTable SearchClient()
{
string connection = ConfigurationManager.ConnectionStrings["DBConnection_Oracle"].ToString();
string procedure = packetName + ".p_search_client";
OracleParameter[] parameters = new OracleParameter[1];
parameters[0] = new OracleParameter("io_cursor", OracleType.Cursor, 4000, ParameterDirection.Output, true, 0, 0, "", DataRowVersion.Current, String.Empty);
DataTable dt = new DataTable();
dt = DataManager_Oracle.GetDataTable_(connection, procedure, parameters);
return dt;
}
It seems that on the Website environment it didn't like leaving out the OUT parameter; whereas on the WebApplication I did not specify it, and it worked just fine... If some one know the why , PLEASE let me know :)

SQLDataAdapter and DataSet

I'm requested to work with a bit of code that uses an SqlDataAdapter, and I was wondering if this is the right approach.(I have looked at the documentation, but it's not totally clear in my mind)
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT * FROM MY_TABLE";
var Adapter = new SqlDataAdapter(cmd);
DataSet Result = new DataSet();
Adapter.Fill(Result);
Edit : think I found what was missing :
connectionString = help.Get_MyConnectionString();
Connection = new SqlConnection(connectionString);
Connection.Open();
Should work better with the connection open -.-"
Yes you need to open the connection. I would also wrap your SqlConnection and SqlDataAdapter in using blocks so that they are properly disposed.
using (var conn = new SqlConnection("YOUR CONNECTION STRING"))
{
conn.Open();
using (var adapter = new SqlDataAdapter(
"SELECT * FROM MY_TABLE", conn))
{
var result = new DataSet();
adapter.Fill(result);
}
}

Transacrtion commit and rollback not working using OracleTransaction

I had search in the internet and not much info I can get. I try to insert data to table database oracle, but it's not working when I use OracleConnection and OracleTransaction to commit and rollback. the following code ;
using (Entities dbContext = new Entities())
{
string constr = "data source=10.10.10.228:1521/MPMBO;password=tax;user id=TAX";
using (OracleConnection orcConnect = new OracleConnection(constr))
{
orcConnect.Open();
OracleCommand orcCommand = orcConnect.CreateCommand();
OracleTransaction orcTransaction;
orcTransaction = orcConnect.BeginTransaction(IsolationLevel.ReadCommitted);
orcCommand.Transaction = orcTransaction;
try
{
MPMISTAX_HDRMASUK item = new MPMISTAX_HDRMASUK();
//something item to include...
dbContext.MPMISTAX_HDRMASUK.Add(item);
dbContext.SaveChanges();
for (int j = 0; j < Id.Length; j++)
{
MPMISTAX_DTLMASUK itemA = new MPMISTAX_DTLMASUK();
//something code
dbContext.MPMISTAX_DTLMASUK.Add(itemA);
}
dbContext.SaveChanges();
orcTransaction.Commit();
}
catch (Exception dbEx)
{
orcTransaction.Rollback();
throw new Exception(dbEx.Message);
}
}}
I can't get error, but the table not insert in database oracle. I hope you can help my problem. Thank you

ExecuteScalar not functioning on server

The application uses Oracle DataAccess ver. 1.1. , VS 2008, .Net Framework 3.5 w/SP1
OracleConnection connection = new OracleConnection(ConnectionStringLogon);
connection.Open();
OracleParameter selectParam = new OracleParameter(":applicationName", OracleDbType.Varchar2, 256);
selectParam.Value = applicationName;
if (connection.State != ConnectionState.Open)
connection.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = connection;
cmd.CommandText = "Select ApplicationId from Applications where AppName = 'appName'";
cmd.CommandType = CommandType.Text;
if (selectParam != null)
{
cmd.Parameters.Add(selectParam);
}
object lookupResult = cmd.ExecuteScalar();
cmd.Parameters.Clear();
if (lookupResult != null)
The procedure fails on object lookupResult = cmd.ExecuteScalar(); with this error:
Event Type: Error
Event Source: App Log
Event Category: None
Event ID: 9961
Date: 9/30/2008
Time: 4:42:11 PM
User: N/A
Computer: Server15
Description:
System.NullReferenceException: Object reference not set to an instance of an object.
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader()
at Oracle.DataAccess.Client.OracleCommand.ExecuteScalar()
at Membership.OracleMembershipProvider.GetApplicationId(String applicationName, Boolean createIfNeeded) in OracleMembershipProvider.cs:line 1626
I've looked at this from every angle that I can conceive of... basically, no matter how I wrap it, the Execute fails.
I notice your CommandText doesn't contain the specified parameter ":applicationName"
It's not an error in "ExecuteReader". It's an error in the execution of the query... is applicationName null?

Resources