oracle clob parameter conversion to string hangs in asp.net - asp.net

Please find this code. It is properly working on my local machine. It was copied to windows server 2008 (64bit). It was working fine for many days. But now, it is hanging and taking 20 minutes. Same code is working in my machine fast. If I convert clob to varchar, it will work, but it will not support more than 32 K. I updated oracle client, now also it is hanging.
Dim cn As New OracleConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
Dim cmd As New OracleCommand
cn.Open()
cmd.Connection = cn
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.CommandText = "Inet_Pkg_Menu.TopMenu"
cmd.Parameters.Add("pBrCode", OracleDbType.Int32).Direction = Data.ParameterDirection.Input
cmd.Parameters.Add("pRes", OracleDbType.Clob).Direction = Data.ParameterDirection.Output
cmd.Parameters(0).Value = Session("user_code")
cmd.ExecuteNonQuery()
Dim s As String
Dim olob As OracleClob
olob = CType(cmd.Parameters("pRes").Value, OracleClob)
s = System.Convert.ToString(olob.Value) 'Hanged line

I'm using Oracle Clob and it is very easy and there is no need to make type conversion, just suppose it as a string in asp.net, and here is an example:
Dim sql = "select xmlagg(XMLElement("user",xmlattributes(user_id "user_id"))).getClobVal() from users" 'this is just example of returning clob value
Dim adp As New Data.OleDb.OleDbDataAdapter(sql, MyConnectionString)
Dim dt As New DataTable
adp.Fill(dt)
Dim data As String = dt.Rows[0][0].toString()
and now in data variable you have the result

Related

Read Data From SQL using Webservice VB.NET

i have a program to read data from sql server using vb .net web service but i have an error when i run my code like this
http://prntscr.com/apmahp
my code
<WebMethod()> _
Public Function TopKill() As Integer
Dim con As New SqlConnection
con.ConnectionString = "Data Source=127.0.0.1;Initial Catalog=RF_User;Integrated Security=True"
Dim killing As Integer
con.Open()
Dim cmd As New SqlCommand(("SELECT TOP 20 Name, [Kill], Death FROM tbl_pvporderview Join(tbl_base) ON tbl_pvporderview.serial = tbl_base.Serial ORDER BY [Kill] DESC"), con)
Dim killreader As SqlDataReader
killreader = cmd.ExecuteReader()
killreader.Read()
If killreader.HasRows Then
killing = killreader.Item("Name").ToString
killing = killreader.Item("Kill").ToString
killing = killreader.Item("Death").ToString
End If
con.Close()
Return killing
End Function ' TOP 20 Killer
i don't know how to fix it.
any one can help me to fix my code
thanks before
Mind the spaces, use the edited query below
Dim cmd As New SqlCommand(("SELECT TOP 20 Name, [Kill], Death FROM tbl_pvporderview Join tbl_base ON tbl_pvporderview.serial = tbl_base.Serial ORDER BY [Kill] DESC"), con)
This should work because there was a space missing after the Join
Hope this helped

Get Oracle.DataAccess.Types.OracleClob instead of actual value

I'm having an issue, I'm calling a procedure on oracle 11g, the prucedure receives a clob and responds with a different CLOB, a VARCHAR2 and a Number. The procedure is called from a ASP.NET (on Visual Basic) webpage using oracle data provider (ODP.NET), I can call the procedure successfully, view the VARCHAR2 and NUMBER returned values, but when I try to see the returned value of the returning CLOB all I get is "Oracle.DataAccess.Types.OracleClob" instead of a expecting XML
I know the returned XML is generated because on the store procedure I create a txt file where it shows the expected result
My code it's pretty simple right now:
Function Index() As String 'ActionResult
Dim xml_message As String
Dim oradb As String = "Data Source=127.0.0.1;User Id=id;Password=pass;"
Dim conn As New OracleConnection(oradb)
Dim oracleDataAdapter As New OracleDataAdapter
oracleDataAdapter = New OracleDataAdapter()
Dim cmd As New OracleCommand
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "Common.GetDriverPoints"
cmd.BindByName = True
Dim driver_input As New OracleParameter()
driver_input = cmd.Parameters.Add("p_driver", OracleDbType.Clob)
driver_input.Direction = ParameterDirection.Input
driver_input.Value = <THE_SENDED_XML_VALUE>
Dim driver_output As New OracleParameter()
driver_output = cmd.Parameters.Add("p_output", OracleDbType.Clob)
driver_output.Direction = ParameterDirection.Output
Dim error_flag As New OracleParameter()
error_flag = cmd.Parameters.Add("p_Return", OracleDbType.Int16)
error_flag.Direction = ParameterDirection.Output
Dim error_desc As New OracleParameter()
error_desc = cmd.Parameters.Add("p_ReturnDesc", OracleDbType.Varchar2, 100)
error_desc.Direction = ParameterDirection.Output
conn.Open()
cmd.ExecuteNonQuery()
Dim output As String
output = driver_output.Value.ToString() 'This only returns Oracle.DataAccess.Types.OracleClob
conn.Close()
conn.Dispose()
Return output
End Function
Also, the generated xml is around 55Kb, sometimes it's bigger
Thank you
I manage to find the answer, In case someone have the same problem, basically what has to be done is create another clob, used only on for vb.net, that clob will receive the value of the parameter output from the procedure, then cast to a string variable the local clob.
Example:
Dim output As String
Dim myOracleClob As OracleClob = driver_output.Value
output = System.Convert.ToString(myOracleClob.Value)
Now the "output" variable holds the actual message of the clob.
Hope this helps anybody with the same problem.

ASP.NET SQL Query look for MAX Value

I would like to fire an SQL Query from my ASP.NET page (vb), what the query will do is to look for the maximum value from a column and then return that value and place it into a label in the webpage.
Currently i dont know to fire the SQL command and then return with the value, a correction to my code is hihgly appreciated.
Dim Con As New SqlConnection
Dim SQL As String
Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True"
Con.Open()
SQL = "SELECT MAX(ID_ControlCharts) FROM ControlCharts"
Label123.Text = SQL
The code above is not working, i know that i need to execute the query however i'm totally lost.
You need to create sql command and call executescalar method.
Ex:
Dim Con As New SqlConnection
Dim SQL As String
Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial
Catalog=MicroDB;Integrated Security=True"
Con.Open()
Dim cmd as new SQLCommand(sql,Con)
Dim obj = cmd.ExecuteScalar()
if(obj!=null)
Label123.Text = obj.ToString()
end if
Con.Close()
Dim com as SqlCommand = Con.CreateCommand
Label123.Text = com.ExecuteScalar(SQL)

A nested SQL query within a while loop in ASP.NET

I intended to do another SQL query inside here and retrieve data from another table by using the "category_id"
I know the problems that asp.net required me to close the data reader before proceed to another query. But is there any solution for me to do another query and open another data reader within the opening data reader?
My current code is as follows...
Dim dr, dr2 As SqlDataReader
Dim conn As SqlConnection
Dim cmd, cmd2 As SqlCommand
conn = New SqlConnection("server=XXX-PC;user=sa;password=abc123321;database=xxx")
cmd = New SqlCommand("SELECT * FROM category ORDER BY category_Name", conn)
conn.Open()
dr = cmd.ExecuteReader()
Do While dr.Read()
Dim category_id As Integer = dr.GetInt32(0)
Dim category_name As String = dr.GetString(1)
/* Another data reader and query here */
Loop
dr.Close()
conn.Close()
You have a few options:
Create a new connection to your database, and create the second data reader from that.
Use a SqlDataAdapter, and dump your queries into in-memory DataTables, and loop through them.
Use an Object-Relational mapper, like NHibernate, or Entity Framework, and obviate all these problems completely.
2 would probably be the simplest, and quickest to implement. 3 will require a bit of a learning curve, but would likely be worth it in the long run. 1 is actually a terrible idea; don't do it. I probably shouldn't even have listed it.
You can use MARS the ultimate feature of vs2005
[Multiple Active Result Sets ]
instead of datareader use Idatareader
Dim dr, dr2 As IDataReader
Dim conn As SqlConnection
Dim cmd, cmd2 As SqlCommand
conn = New SqlConnection("server=XXX-PC;user=sa;password=abc123321;database=xxx")
cmd = New SqlCommand("SELECT * FROM category ORDER BY category_Name", conn)
conn.Open()
dr = cmd.ExecuteReader()
Do While dr.Read()
Dim category_id As Integer = dr.GetInt32(0)
Dim category_name As String = dr.GetString(1)
/* Another data reader and query here */
cmd2.CommandText=” your query”
dr2 = cmd2.ExecuteReader();
Loop
dr2.Close();
dr.Close()
conn.Close()
MARS is disabled by default on the Connection object. You have to enable it with the addition of MultipleActiveResultSets=true in your connection string.
Create a Separate function, and create private data adapter & data set into it and perform your logic then return value to main procedure.

how can we retrieve data from database in ASP.NET using VB as language?

i need the complete code for retreiving the data from a database.. i m coding in visual web developer and using VB as coding language. I m using SQL SERVER as database handler.
Shared Dim con As SqlConnection
Shared Sub Main()
con = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI")
' Create the command object
Dim str As String = "SELECT ID, FirstName, LastName FROM Employee"
Dim cmd As New SqlCommand(str, con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "Employee")
gridview1.datasource=ds;//
gridview1.databind();// to bind the data to gridview
its will be help to u..
Samples here might work for you

Resources