How to retrieve Output parameters with ADO Command and Oracle Stored procedure - asp-classic

I'm setting up a new web server on windows server 2012 R2 with IIS8. The Database server has Oracle 12c version.
I'm trying to retrieve the output parameters of a stored procedure using Classic ASP page with ADODB.Command.
I've created a simple procedure (with a single output parameter).
I've checked on DB side that the procedure is correctly executed looking the relative session browser with a DB tool.
==============================
This is the Procedure Code:
CREATE OR REPLACE PROCEDURE test_me (w_count OUT NUMBER)
is
begin
w_count := 1;
end;
/
=============================
Here the ASP page code
var conn = Server.CreateObject("ADODB.Connection");
var statusCmd =Server.CreateObject("ADODB.command");
conn.Open(strConnect);
conn.BeginTrans();
statusCmd.ActiveConnection = conn;
statusCmd.CommandText = "{call" + " test_me(?)}";
statusCmd.CommandType=1;
statusCmd.Parameters(0).Direction = 2;
statusCmd.Execute();
Response.Write(statusCmd(0).Value + "#");
conn.CommitTrans();
I'm expected to see (in this simple case) the Output on the page: 1#
The actual result is: undefined#
The server is a new one web server and should be all correctly configured but I'm not 100% sure so if you think there are some missing on the installation / configuration don't hesitate to ask.

Related

SQL works in R studio but not in R-Serivces

This code works perfectly in R-Studio but there is no way to make it work in MS Management studio. It keeps on saying that:
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'myserver\LOCAL01'.
That is not my user give it is a trusted connection. Can someone help me understand it?
ALTER PROCEDURE [dbo].[TESTIM] AS
BEGIN
SET LANGUAGE ENGLISH
CHECKPOINT 
DBCC DROPCLEANBUFFERS
EXEC sp_execute_external_script
#language = N'R'
, #script = N'
con <- "Server=myserver\\LOCAL;Database=mydb;Trusted_Connection=true";
sql <- RxInSqlServer(connectionString = con, shareDir = "c:\\TMP");
local <- RxLocalSeq(sql);
rxSetComputeContext(local)
ff <- RxSqlServerData(sqlQuery = "select top 1 * from mytable", connectionString = con);
t = rxImport(ff);
OutputDataSet <- data.frame(SUCCESS = TRUE);
'
WITH RESULT SETS (([SUCCESS] BIT))
END
So, when you execute sp_execute_external_script it executes under one of 20 Windows user accounts (worker accounts) that has been created during installation of SQL Server R Services. These accounts are created for the purpose of running tasks under a security token belonging to the SQL Server Trusted Launchpad service.
This works very well, but if you need to create a SQL connection inside your R script (as in your case) and you use trusted connection (Windows Authentication), you are executing under the user account mentioned above ('myserver\LOCAL01' in your case), and that account need to be given permission to log in to the SQL Server instance on your behalf.
To do this:
In SQL Server Management Studio, in Object Explorer, expand Security, right-click Logins, and select New Login.
In the Login - New dialog box, click Search.
Click Object Types and select Groups. Deselect everything else.
In Enter the object name to select, type SQLRUserGroup and click Check Names.
The name of the local group associated with the instance's Launchpad service should resolve to something like instancename\SQLRUserGroup. Click OK.
By default, the login is assigned to the public role and has permission to connect to the database engine.
Click OK.
That should do it (the above steps are copied from here.
If you want to read more about the user accounts you can have a look at my blog-post "Microsoft SQL Server R Services - Internals III".
Hope this helps!
Niels

Database connection and querying in ASP.NET

Okay, so after about an hour of searching through the web, I'm still having issues trying to create a local DB connection in ASP.net.
I need to create a connection to a local database file, and then simply loop through each record in a table. I'm not sure which file extension to use here (.aspx, .vbhtml, .cshtml?)
This is what I currently have from this W3school tutorial,
' Create local connection to DB file
#{
var db = Database.Open("Properties.mdf");
var query = db.Query("SELECT * FROM Properties");
}
<div id="pagewrap">
' Loop through records
#foreach(var row in query)
{
<p>#row.StreetAddress</p>
<p>#row.City</p>
<p>#row.State</p>
}
</div>
I'm currently getting a Connection string "Properties.mdf" was not found. error when running the above code. Any help is greatly appreciated.
That is because "Properties.mdf" is not a connection string. The mdf file cannot be opened just like this on its own - it needs a proper sql server database service. Exemplary connection string could look like this
var db = Database.Open("Server=.\SQLExpress;AttachDbFilename=Properties.mdf;Database=mydatabase;Trusted_Connection=Yes");
Although you need to have sql server installed (in this case your sql server instance would be called SQLExpress). and the connection string highly depends on what version of SQL Server you want to connect to.
Please refer to MSDN article.

classic asp async sql execution

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

"String or binary data would be truncated" in uploading file in ASP.NET MVC3

I'm developing some application in ASP.NET MVC3 and trying to upload some file in SQL Server 2008, I have the type varbinary(MAX) in DB and I have the code below for uploading it, but I get the error "String or binary data would be truncated . The statement has been terminated" which I believe it's a data base error, where do you think my problem is? thanks
if (UploadedFile != null)
{
App_MessageAttachment NewAttachment= new App_MessageAttachment { FileName = UploadedFile.FileName, FilteContentType = UploadedFile.ContentType, MessageId = NM.Id, FileData = new byte[UploadedFile.ContentLength] };
UploadedFile.InputStream.Read(NewAttachment.FileData, 0, UploadedFile.ContentLength);
db.App_MessageAttachments.InsertOnSubmit(NewAttachment);
db.SubmitChanges();
}
That is a database error, but it isn't necessarily associated with the file portion of the insert. Check to make sure that FileName, FileContentType, and MessageId are all short enough to fit within their fields in the database.
I would start with Management Studio -> Tools -> SQL Profiler.
Point it at your database and run the upload again. Press pause or stop after you see the error in your app and search for the error message within the trace window. This will give you the SQL that generated this message. If the solution doesn't immediately present itself to you, edit your post with the statement that failed.
Here are some Profiler resources
SQL Server Profiler Step by Step
How To: Use SQL Profiler

BizTalk Generate Metadata Fails with Stored Procedure

I am trying to set up the SQL Adapter in BizTalk 2009 to use a Stored Procedure in our SQL 2008 DB. For some reason, when I click "generate" in the wizard, and then click "next," I receive the following message:
Failed to execute SQL Statement. Please ensure that the supplied syntax is correct. New Transaction cannot enlist in the specified transaction coordinator.
I know the stored proc works, because we call it from C# code as well and I don't have a problem with it. I'm pretty sure I'm missing something basic, but I can't find what it is, and the only information I can find on using Stored Procs through the BizTalk SQL Adapter only show Select statements, so I don't know if there's some other setting I"m missing.
Here's the Stored Proc:
SET NOCOUNT ON;
Declare #Client int
set #Client = (Select Client_Id from Clients where Client_Name = #clientName)
Insert Into [FTP_Data].[dbo].[FileLog](Client_Id, Client_Name, FileType, Received)
Values(#Client, #clientName, #fileType, GETDATE());
Edit/Update: When I move the solution off my developer box and onto the actual server box, it works fine. As far as I can tell, the only difference is that the actual BizTalk Server components (instead of just the developer stuff) are on the same machine as the SQL Server to which I'm connecting. I would think that should be an issue, though...
"New Transaction cannot enlist in the specified transaction coordinator". Seems to indicate a possible DTC error. Is this the SQL server that the BizTalk databases are installed on?

Resources