classic asp async sql execution - asp-classic

I have a classic asp application (ASP 3.0 running on Windows 2000/IIS 5.0) which allows users to write custom SQL queries to fetch data from the database (Oracle 10g), more like SQL Developer. Sometimes users write complex queries which runs indefinitely, though the user would click the back button to go back to previous page, the query might still run on the database. Now users are requesting they be given a functionality to kill the query on a click of a button.
I am beginner in asp, so I am not sure if this is possible in asp. We are using ADODB.RecordSet object to fetch the data using RecordSet.Open and RecordSet.GetRows. Please advise if this is achievable in classic asp.
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open DATA_SOURCE, LOGON_ID, PASSWORD
Set resultset = Server.CreateObject("ADODB.Recordset")
Dim sql
sql="select sysdate from dual"
resultset.Open sql, connection
Dim DBData
DBData = resultset.GetRows(NUMROWS)
resultset.close
connection.close
Set resultset = Nothing
Set connection = Nothing

Try this
arrayRs = resultset.GetRows()
if arrayRs(0,0)<> "" then
response.write(arrayRs(0,0))
end if
Or you can try a loop when you are fetching more than one field

Related

SQL Login fails from web application for one stored procedure call

Fortunately, this is in UAT rather than production.
The UAT servers are Azure VMs running SQL Server 2012 and Windows Server 2012.
On one page in the application I get an error
Login failed for user 'User'. at System.Data.SqlClient.SqlInternalConnection
Microsoft.ApplicationBlocks.Data.SqlHelperParameterCache.GetSpParameterSetInternal(SqlConnection connection, String spName, Boolean includeReturnValueParameter)
at Microsoft.ApplicationBlocks.Data.SqlHelperParameterCache.GetSpParameterSet(String connectionString, String spName, Boolean includeReturnValueParameter)
at Microsoft.ApplicationBlocks.Data.SqlHelperParameterCache.GetSpParameterSet(String connectionString, String spName)
The login is a SQL Server login, not a domain login
On the SAME web page, there are 3 other stored procedure calls that are made to the same database with the same connection string prior to this stored procedure begin called
I have dropped and recreated the stored procedure
I have dropped and recreated the database login
The account is a member of a database role that grants it EXECUTE rights on the schema this stored procedure belongs to
If I log into SSMS as this user, I can:
Expand the stored procedure list for the database
Expand the parameter list for the affected stored procedure
Run the affected stored procedure and get the expected results
I have an alternative web server set up on the SQL Server which uses domain logins in the connection string, that runs with no problem. We are trying to deprecate the SQL Server version of the web site.
Can anyone suggest what might be causing this, and how to address it?
Thanks you .NET SqlClient security behaviour.
Working call via Data Application block
return SqlHelper.ExecuteReader(ConnectionString, sql_OutboundQueue_TypeAndStatusCount, DBUtility.GetNull(since));
This chains down to calling SqlHelperParameterCache.GetSpParameterSet
Failing call via Data Application block
SqlConnection con = new SqlConnection(QueueDataProvider.ConnectionString);
SqlCommand cmd = new SqlCommand(QueueDataProvider.OutboundQueue.sql_OutboundQueue_Search, con);
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(SqlHelperParameterCache.GetSpParameterSet(con.ConnectionString, cmd.CommandText));
Reason:
con.ConnectionString has the password cleared if you are using SQL Logins, but only AFTER you call con.Open
Thanks to: ConnectionString loses password after connection.Open

ADODB Connection String not working in Classic ASP

I have been developing an ASP.NET application. I want to integrate Classic ASP file(.asp) in this application.
In a .asp file I have to fetch data from SQL Server 2008 r2 database.
For this I have created db and rs object. I have passed ConnectionString in db.Open function. But I am getting no output for this code.
Following is my code
set db = Server.CreateObject("ADODB.Connection")
db.Open "provider=SQLNCLI10;Data Source=HP-PC\SQLEXPRESS;Initial Catalog=RMToday;Persist Security Info=True;"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "select * from RMToday.dbo.[Current]",db
if not rs.EOF Then
response.Write(rs("DayClosed"))
End If
I have searched in stackoverflow.com and got some related questions, answer.
I can not understand the wrong in this code.
Thanks in advance

oracle ExecuteNonQuery freezes on ASP.Net

I am trying to run a non query using a Oracle connection in ASP C# with CLR 4.5. Here is my code:
string connectionString = ConfigurationManager.ConnectionStrings["OracleConnectionString1"].ConnectionString;
OracleConnection conn = new OracleConnection(connectionString);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "update SALES_ADVENTUREWORKS2012.SALESORDERDETAIL set UNITPRICEDISCOUNT=0 where ROWGUID='4A399178-C0A0-447E-9973-6AB903B4AECD'";
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = QUERY_TIMEOUT;
int row_affected = cmd.ExecuteNonQuery();
HttpContext.Current.Response.Write("Rows affected:" + row_affected + "<br/>");
conn.Close();
when I run the query in oracle development tool, it works fine.
when I use the asp code above, it freezes when performing the query. It freezes forever even though I used a 5 second timeout.
I've tried using the managed and unmanaged oracle libraries; both behave the same.
Note that using the fill or scalar query work perfectly fine so there is nothing wrong with my connection string. Also the fact that oracle development can perform this update query proves that this is not a permission problem.
Any ideas?
Most likely your query is waiting to get access to the record. You probably have modified that row in "oracle development tool" and have not committed or rolled back that transaction.
Just commit/rollback in your tool or close open session.
You can check for open transactions in v$transaction view.
More on automatic locks in Oracle:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/ap_locks001.htm
Are you certain you are using the 4.5 library? The 3.5 documentation states that the CommandTimeout property has no effect.
The 4.5 documentation suggests it should work, but the Remarks section doesn't mention the change, which warrants suspicion.
Otherwise, the code you posted doesn't seem to show where you actually set the value of QUERY_TIMEOUT to 5 seconds. If QUERY_TIMEOUT has a value of zero, then any other provider (SQLCommand, for example) would wait indefinitely. As vav suggested, locks from other sources could cause an indefinite wait.

How to access SQL Server from my WCF web service?

VS Express 2012, SQL Server Express 2012, Win 8.1
Hello,
I have a (very) simple WCF hosted as a web service on IIS. I also have a SQL Server instance (with 1 table) installed on the same machine.
I need a step-by-step guide on how to connect to SQL from the WCF (VB) and retrieve a single record from the table (ie: "SELECT LAST NAME FROM MYTABLE WHERE PK = 1;"). That's it. I don't need a 1,200 page manual -- which is all Google keeps throwing at me.
Anyone know of a quick, clean resource?
Thanks,
Jason
The main classes that are involved are SqlConnection and SqlCommand. The documentation of the classes contains some samples on how to use them. To get you started, here is a small sample:
Dim connStr = "Data Source=SQLServerName\InstanceName;Initial Catalog=DatabaseName;Integrated Security=SSPI"
Using conn As New SqlConnection(connStr)
conn.Open()
Using cmd = conn.CreateCommand()
cmd.CommandText = "SELECT LAST_NAME FROM MYTABLE WHERE PK = #pk"
cmd.Parameters.AddWithValue("#pk", 1)
Dim result = cmd.ExecuteScalar()
If Typeof result Is DbNull Then
' Handle null value
Else
' Otherwise
End If
End Using
End Using
This sample assumes that you want to retrieve a single cell as in your statement. If you want to retrieve tabular data, have a look a the SqlDataReader or SqlDataAdapter class.
Please note that - especially in server applications - it is important to dispose of the created instances properly.
There is no difference on using ADO.NET in a WCF service or in a normal application from the point of view of the classes required.
The first thing needed is a connection string that allows your SqlConnection object to find the host and the database that you want to use. Here examples on connection strings
Then you usually need a SqlCommand that encapsulates the SQL text and parameters needed to retrieve the data (Here you setup your SELECT statement and conditions)
Finally you need a SqlDataReader that get the result of the command execution and allows you to loop over the results.
Here a sample that could get you started.
Keep in mind that this is just a minimal todo-list and there are numerous other ways to work with data. Basic objects like SqlDataAdapter, Dataset, DataTable present different ways to load data from a database and use that data. Then on top of these there are technologies like Linq To Sql and Object Relational Mapper tools that abstract the data access and offer high level functionality on top of data.
That's probably the reason you get so much informations on data access technologies

Convert Access data base to SQL Server

I've created an application using ASP.NET with Access DB, now I found somee.com who support only SQL Server DBs, so Now I must convert my Access DB to SQL Server DB.
Is there any tool who can do the trick ?
This is some code I'm using in my web application :
Public Shared Function conecter() As OleDbConnection
Dim MyConnexion As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & System.AppDomain.CurrentDomain.BaseDirectory & "/Learning.mdb")
MyConnexion.Open()
Return MyConnexion
End Function
Public Shared Function lecture(ByVal requete As String) As OleDbDataReader
Dim Mycommand As OleDbCommand = conecter().CreateCommand()
Mycommand.CommandText = requete
Dim myReader As OleDbDataReader = Mycommand.ExecuteReader()
Return myReader
End Function
In this case, If I convert my database I must change the OleDbConnexion and other things or I can just leave them like that ?
Your connection string will need to change. Connectionstrings.com is a good resource for this if you're having problems figuring out how to set up a SQL connection string.
For upward migration, take a look at the Access Upsize Wizard - this link is for 2002 since I'm not sure what access version you have.
If for some reason you do not have sufficient access to your SQL database to handle an upsize directly, you'll likely need to just generate the database schema and knock out a bit of migration code.
If you have access 2007, there is inbuilt option convert access database to SQL other wise there are somany tools available for free.
bullzip free converter
Try MUST
It was developed by a colleague of mine (we designed the website: www.upsizing.co.uk).
It does a fair bit more than the MS tools.

Resources