How to connect Active Reports 7 to use a stored procedures? - stored-procedures

How to connect Active Reports 7 to use a stored procedures? I have stored procedures already written, but how do you connect to them to use the data in the tables so that my report is dynamic.

ActiveReports 7 has two different report types, with slightly different ways of using stored procedures.
If you are using a SectionReport (i.e. the traditional form of report that was available in ActiveReports 6) then you can execute a stored procedure via the EXEC SQL command in your query. f.e.
EXEC sp_mysp '<%myparameter%>'
In a PageReport (i.e. the new report type introduced in ActiveReports 7) then you need to set the command type to Stored Procedure and then the query string is set to the name of your stored procedure. If you have any parameters to pass then you can pass them in via the DataSet's parameters page.
In PageReports when working with the ADO.NET based data providers (SQL Server, OLE DB, and Oracle connection types) there is a 1-to-1 correlation between objects in the data source, data set, and parameters in Page Reports and what you see in the related ADO.NET *Connection, *Command, and *Parameter classes. So if you have questions about how those work you can just look at how you would write the same code with the ADO.NET classes.

Related

Avoiding hard coding Schema in DB2/400 Stored Procedure

I'm creating Stored Procedures to replace Legacy app programs for an IBM i. I'm calling the stored procedure from a Java Web App. I'm using the jt400 JDBC driver
My JDBC URL is jdbc:as400://myhost/;libraries=*LIBL,MYLIB;prompt=false
The stored procedures can call stored procedures
The initial stored procedure call completes normally if it does not make further stored procedure calls
If the stored procedure makes a call to other stored procedures it fails with
com.ibm.as400.access.AS400JDBCSQLSyntaxErrorException: [SQL0204] MY_SP in MYLIB type *N not found.
If I hard code a schema in the stored procedure call statement, the call completes normally.
I want to have the called stored procedures use the same schema as the caller
You need to SET PATH = "MYLIB"
When I am using SQuirreL to call a stored procedure, I need to use the SET PATH statement to get it to find the stored procedure. I don't know if that is because my library list is bad or what, but the current schema is not used to find an unqualified stored procedure.
I actually had this same problem, the stored procedure uses your job description library list. You need to edit that you can use TAATOOL CHGLBLJOBD. I am not in front of an iSeries at the moment but I believe the command was either EDTJOBDLIB or EDTJOBDLIBL WRKJOBDLIBL. It is some variation of that.

Entity Framework Core Database Table Valued Functions Mapping

I use EFCore 2.1 Database First approach. I'm pretty familiar with SQL syntax and prefer build queries myself rather then leave this work on EF. I use Table Valued and Scalar Functions for querying the database.
I found this for Scalar
https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-2.0#database-scalar-function-mapping
But unfortunately nothing about Table Functions.
Is there any way to force Visual Studio grab all Table Functions and Scalar Functions and Stored Procedures from SQL Server, when I run Scaffolding?
I was using LINQ to SQL dbml designer before. Everything was extremely simple with dbml. You drag from Server Explorer drop to dbml and boom, I can use SQL Function or SP like regular C# method.
Any chance to reproduce this in EFCore?
There's no reverse engineer (aka DbContext scaffolding) support for it, but you can use FromSql() to query using table-valued functions. See these docs.
var searchTerm = "EF Core";
var blogResults = db.Blogs.FromSql(
"SELECT * FROM dbo.SearchBlogs({0})",
searchTerm);
Source : https://www.allhandsontech.com/data-professional/entityframework/entity-framework-core-advanced-mapping/
Use HasDbFunction to do a mapping, refer Microsoft doc
It requires return types to be declared as Keyless entity using HasNoKeyMicrosoft doc
Configure EF Context to expose Db function
modelBuilder.HasDbFunction(typeof(SalesContext)
.GetMethod(nameof(NameAndTotalSpentByCustomer)))
.HasName("CustomerNameAndTotalSpent");
modelBuilder.Entity<CustWithTotalClass>().HasNoKey();
Invoke Db function in calling code
_context.NameAndTotalSpentByCustomer().Where(c=>c.TotalSpent>100).ToList();
Generated SQL
SELECT [c].[Name], [c].[TotalSpent]
FROM [dbo].[CustomerNameAndTotalSpent]() AS [c]
WHERE [c].[TotalSpent] > 100

SqlEntityConnection (Entity Data Model) TypeProvider

I am using the SqlEntityConnection (Entity Data Model) TypeProvider to connect to a SQL Server database that has a few tables and stored procedures.
#if INTERACTIVE
#r "System.Data"
#r "System.Data.Entity"
#r "FSharp.Data.TypeProviders"
#endif
open System.Data
open System.Data.Entity
open Microsoft.FSharp.Data.TypeProviders
// You can use Server Explorer to build your ConnectionString.
type internal SqlConnection = Microsoft.FSharp.Data.TypeProviders.SqlEntityConnection<ConnectionString = #"DataSource=server etc">
let internal db = SqlConnection.GetDataContext()
According to the documentation provided by a link in the template file - http://go.microsoft.com/fwlink/?LinkId=229210
"Get the data context, which is an object that contains the database tables as properties and the database stored procedures and functions as methods."
db should have the stored procedures in the database as methods. However, I can only see the tables in the database as properties of db.
What am I missing?
I think the documentation is incorrect. The SqlEntityConnection TP uses the tool edmgen.exe in the backend to do the actual codegen and heavy lifting, and from what I can tell that tool doesn't support including stored procedures as part of the generated proxy classes. Here's another SO question asking about exactly this, sadly no replies.
Running
edmgen.exe /mode:FullGeneration /connectionstring:"..." /language:CSharp /p:EdmTest
outputs various files, only one of which (the .ssdl file) contains any information about the stored procedures present in my DB.
The SqlDataConnection TP definitely does support stored procedures, in case that's a possible alternative for you.

How to call stored procedure with input parameters in ADO.NET Entity Framework 4 in ASP.NET 4.0

I am using Database first modal and EF4.0.
I have created a stored procedure which required two input parameters and return dynamically column in result-set i.e. columns are not fixed in result.It may be 5 or 7 or 10 and so on.
I am using Grid-view and passing the result-set in it's data-source.
How can i call stored procedure in this case.
thanks.
You must use ADO.NET and data reader / data adapter directly. EF can work only with stored procedures producing strongly typed results known at design time (you must create class for them).

Extract query definition from JET database via ADO

I have a program in Delphi 2010 that uses a JET (mdb) database via ADO. I would like to be able to extract the definitions of some of the queries in the database and display them to the user. Is this possible either via SQL, some ADO interface, or by interrogating the database itself (I don't seem to have rights to MSysObjects).
Some of that information is available via ADOX calls. There is an overview of the api with some examples (unfortunately not in Delphi) on the MSDN website.
Basically what you will want to do is to is to import the ADOX type library, and then use the wrapper that is generated for you to access the underlying API. From there its as simple as navigating the hierarchy to get at the data you need.
You will need to access the specific View object, and from there get the command property.
Via DAO, it's pretty easy. You just extract the SQL property of each QueryDef. In DAO from within Access, that would be:
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Set db = DBEngine.OpenDatabase("[path/name of database]")
For Each qdf In db
Debug.Print qdf.SQL
Next qdf
Set qdf = Nothing
db.Close
Set db = Nothing
I don't know how to translate that, but I think it's the simplest method once you're comfortable with using DAO instead of ADOX.
I don't use ADO at all, but I'm guessing that it has a collection of views and the SQL property would work for SELECT queries. However, if you're interested in getting the SQL for all saved QueryDefs, you'd also need to look at the DML queries, so you'd have to look at the stored procedures. I would have to look up the syntax for that, but I'm pretty certain that's how you'd get to the information via ADO.

Resources