There are only one option to establish the connection to the database: ADO.NET . This is a native method of the generator and is recommended, since it allows generating multi-tier Windows applications, enables statement caching, offers application monitoring tools, and implies using 100% “.NET managed code” to access the DBMS.
To setup the connection to the database you must set the following:
- Connection values from “Access technology to set” = ADO
When working with ADO.NET the entire logic is in gxclasses.dll. As regards the DBMSs, each of them uses a Data Provider to access the database; each DBMS has its own Data Provider for ADO.NET access.
Previous versions of .Net generator, allowing ODBC connection, but now is not supported
The use of ADO.NET as method for the connection to the database by the .NET generator, has enabled the possibility of performing statements caching. This implies scanning the table once and, in the following queries, go to a “cache” memory with the results of this already executed statement instead of scanning the database again.
<o:p> The “cache” concept applies to a fast-accessed intermediate memory, where most frequently used data can be saved. As regards applications that query the database, the concept deals with keeping the query results on the tables in the memory. This results in avoiding connection costs and everything implied in “bringing” data from the server. </o:p>
<o:p> When making a query for the first time, the result remains saved in memory, as shown in the following figure: </o:p>
<o:p></o:p>
In a second instance, when making the query again, no communication whatsoever with the database server is required:
<o:p></o:p>
Although the “cache” is performed at statement level, it is setup at table level, allowing to select the time while data will persist in memory before having to search for them again in the database.
This implies that all statements affecting a table will be cached depending on the value of this table. If the time has expired, the database is accessed to obtain the data again and store them in the “cache”.
To enable ADO.NET statements “cache” and setup the corresponding properties you must go to the “General/.NET specific/ADO.NET specific” section of the model properties.
The .Net platform is quite strict regarding types checking, both in compilation and in runtime, the generator is in charge of doing as many “casts” and conversions as possible. Nevertheless, errors may occur because of wrong programming (the most common one is the overflow in numeric types).
Some considerations are required in the mail data type:
- The data type to manage the mail in “Internet” modality (SMTPSession, POP3Session) and Outlook is implemented.
<o:p> - In web environment, you must setup the following to use Outlook mode: </o:p>
o User impersonate
o Setup Internet Information Service (IIS) virtual directory, for it to use a user with rights on an e-mail account in Outlook (editing the properties \Directory Security\Edit) <o:p> </o:p>
Implementation
GXMail.dll: An assembly .Net that implements the entire Mail management
Before GeneXus 9.0 upgrade 2, the implementation was in:
GxOffice2net.dll is the one used from the programs.
Interop.GxOffice2lib.dll is gxoffice2 wrapper. It is always required.
GxOffice2.dll is the implementation when using Outlook mode. <o:p> </o:p>
The program executing the reorganization is the reor.exe assembly, created under the bin directory.
It takes the specifications from reorganization.dll and checks the presence of the reorgpgm.gen file (a flag). This is necessary when you must execute reorganizations or generations of the database in the production server.
The information on the database connection is in the client.exe.config file. This is valid for both GUI and Web models.
The files required only for the creation/reorganization are the following:
GxClasses.dll, log4net.dll, Reor.exe, Reorganization.dll, reorgpgm.gen, messages.<language>.dll,
Since Gxxev2 or higher , three other files are required
Reor.exe.config, Runx86.exe, Runx86.exe.config
<o:p> Executing the reorganization without interface with the “nogui” parameter is possible. The command syntax is: reor.exe –nogui</o:p>
The “Transactional Integrity” property is not taken into account with ADO.NET. Objects are always generated with transactional integrity, with the exception of the database reorganizations (with Autocommit).
The .NET generator supports multi-level transactions, but every .NET transaction must have a maximum of one flaT level and at least one. 1-level transactions with subfile are not supported. E.g.: structures of the following type are not supported either: <o:p> </o:p>
A*
B
(C*
D
(E*
F))
<o:p> It is to be pointed out that what is not supported is the generation of the program corresponding to the transaction for the transaction execution, but these transactions are supported as regards the structure design of the databases determined by them. That is to say, you cannot execute transactions with these structures in .NET, but they are taken into account to create and reorganize the database. <o:p> </o:p></o:p>
This feature is not implemented; therefore, generating HTML files with the information obtained from the database is not possible.
Store procedures are a specific type of external objects, for that reason it is simple to invoke in a code like this:
&sp1.method(&parm1, &parm2)
where &sp1 is based on external Object data type
For more information please refer to external object
Compatibility previous version : Like in the rest of the generators, to call a “sp1” stored procedure, it must be defined within the “List of remote programs” model property. To call it in the GeneXus code, programming the following is enough:
call('sp1', parm1, parm2)
Parameters must be defined in the extprog.ini file, where the name of the parameters defined in the DB is mapped; e.g.:
[storeproc]
ProgramName=Sp1
ProgramType=StoredProcedure
ParmMode=inout,in
ParmType=Number,5,0;Number,5,0;
ParmName=parm1,parm2
<o:p> In previous versions, when working with ADO.NET, there was the constraint that the variables had to have the same name as the parameters of the Stored Procedure being called and all parameters had to be inout type. </o:p>
<o:p> In the case detailed above, in the Database, sp1 Stored Procedure must have two parameters called @parm1 and @parm2 (both inout type).</o:p>
The submit command uses a Thread pool instead of creating a new thread each time. This limits the number of threads that can be created, thus avoiding a potential overload problem. It is used whenever a submit is done and there are 25 threads per processor. In ASPNET, you can setup the number of threads (in processModel of config) but not in a win application, unless the host is rewritten. If the thread dies for any reason, an error occurs in the log event. This is could be one of the reason of generating the submits as queued components.<o:p> </o:p>
COM+ is a service infrastructure that supports component execution.
Some of the services are: automatic transactions, queued components, object pooling, and others. In .NET, COM+ components may be implemented.
<o:p> “Object Pooling”, for instance, enables you to have a “pool” with N objects. When an object is needed, it is withdrawn from the “pool”, and returned to it when it is no longer used. This stops you from incurring in "costs" for creating and killing objects in each call, which can actually be costly depending on what an object requires (for instance a connection to the DB).</o:p>
In the architecture of GeneXus three-tier applications, the impact of this is relative, since the greater cost accounts for connection, and GeneXus has a pool of connections that is reused with different objects.
It works like a procedure called with Submit. Instead of being run in another thread, it is placed in a queue of a COM+ service, which is in charge of instantiating and running it.
If it is not possible to run it for some reason, (application error, unavailable resources), there are 5 attempts, and if there is still failure, it is sent to a special queue of “failed” objects. This is useful when you want to ensure process execution, regardless of the moment of execution. Furthermore, it is executed in a process different from the caller process. <o:p> </o:p>
- Message Queuing installed (comes with Windows, but it is not installed by default). For installing it, it is necessary to access Control Panel/Add-Remove Programs/Add-Remove Windows Component<o:p> </o:p>
This implementation is only valid for procedures.
For GeneXus objects to be generated this way, they must meet the following requirements:
· They must be defined as main object (Object property “Main object = true”)
· “Assembly” must be put together with “Strong name” (Model property “Strong name = true”)
· It cannot have layout
If any of these requirements is not met, the object is generated with no possibility for it to be called as “Queued component”, and the Submit is done by raising another Thread.
Together with an object, information is generated for its settings, which is included in the COM+ application, when registered.<o:p> </o:p>
This type of assembly runs in a COM+ application; therefore, it is necessary to set it up as such. In order to do that, the following is required:
<o:p>· The security settings are automatically generated by the generator; it generates a scheme without authentication (the most common way of testing an application)
· Registration. The COM+ component must be registered with the following command:</o:p>
“regsvcs <assembly name>”
For example: regsvcs bin\aprc01.exe.
This creates the COM+ application (with the model name), and sets it up with security and generated transactional scheme. Regsvcs is a tool from the .NET Framework that is useful for registering assemblies as COM+ applications.
Moreover, client.exe.config must be copied to the Windows system directory (typically Windows\system32).<o:p> </o:p>
· Everything that is COM, DCOM and COM+ is setup from Control Panel/Administrative Tools/ Component Services<o:p> </o:p>
· Security settings
They are not necessary if an application has been registered as indicated in “Settings, execution”. For testing, the most common thing is a MSMQ workgroup installation (that does not require domain controller). In this type of installation, there is no “Active directory store” against which to authenticate callers, and therefore, it is necessary to deactivate authentication (otherwise it will give “Access denied” when making the call). In order to deactivate authentication from Component services/Computers/My Computer/COM+ Applications, press right button on the properties/security application, unselect the “Enforce access checks for this application” checkbox, and setup “Authentication level for calls” in “None”. This settings are generated by the generator, and occur when a component is registered. Settings for production depens on each installation. In general, it has a domain controller and security must be setup.<o:p> </o:p>
· Setup transactional support
This is not necessary if an application has not been registered as indicated in “Settings, execution”. Inside the COM+ application, go to Components, select the one that corresponds to the GeneXus object, press right button, properties/transactions, set “Transaction support” in “Not supported”. This settings are generated by the generator when a component is registered
There are some specific settings for those PDF reports that are configurable through PDFReport.ini configuration file.
Like with the other generators, it is possible to include language native code in the generated programs. The CSHARP command is used for this.
The syntax consists in adding the CSHARP as a code prefix. <o:p> </o:p>
I.e:
<o:p>CSHARP [!&var2!] = (long)Math.Sqrt([!&var!]);</o:p>
In order to invoke an assembly you could import this file and programming a code like this
&ext.method(&parm1, &parm2)
where Ext is based on an external object data type
For futher information please refer to External Object Example: Native Object (.NET)
Compatibility previous version: Another option to include user .Net native code is to call an external function. For this, you must define a csharp program (.cs) and call the function with:
call('FuncExt', par1, par2)
This is translated to C# code:
new funcext(ref _Context).execute(ref AV8par1, ref AV9par2)
<o:p> Considerations:
- There must be a class with the function name
- This must have a builder that receives a IGxContext type parameter (namespace GeneXus.Application must be included
- There must be an execute method that receives the parameters as reference.
- All names are always in lower case. </o:p>
For further information refer to appendix and/or this complete example at: http://www.gxopen.com/gxopen/servlet/projectinformation?395
The security scheme for .NET Assemblies (dlls y exes) is a rather complex one, although it is also quite secure. To configure the development environment, we need to take some considerations into account.
To be able to work with remote models, we need to disable the .NET security control. Otherwise, it is not possible to execute locally the web objects located in another PC through the network; i.e.: to execute, in the web server, objects that are not physically in the same PC. This is a security restriction of the .Net Framework.
This only involves the development environment. In the final installation (where the server and the DLLs are in the same PC) this is no longer necessary and, in fact, disabling the security measures is not recommended at this stage.
How should this be done? To inhibit security, the "caspol -security off" command must be executed in the PC where the objects will be executed. This command is set by PC, and does not affect objects generation, only the execution in the development environment. If the objects to be executed are in the same PC, this process is not necessary. In the future, the configuration of security policies regarding the code will be supported at object level.
To execute reorganization that is an assembly (reor.exe), if it is run from some intranet PC it will not have all the required resources.
<o:p> The assembly has different security levels according to the site where it is located:
My Computer: Full Trust (programs are completely reliable and can access all the required resources).
Local Intranet : they have a different level, lower than the one of Full Trust; thus, they cannot access a group of resources such as the file system.
Internet: They have the lowest reliability level and in general they cannot perform tasks without the approval of the user. </o:p>
To solve this problem:
1) Move to the directory
<<st1:street w:st="on"><st1:address w:st="on">SYSTEM DRIVE</st1:address></st1:street>>:\<WINDOWS FOLDER>\Microsoft.NET\Framework\<Version Number>\
2) Execute the command
mmc mscorcfg.msc
this opens the console: ".Net Admin Tool"
Among other things, there is an entry for "Runtime Security Policy"
Then, go to the link: “Adjust Zone Security”Select the Intranet zone and increment the security level to “Full Trust“
<o:p> </o:p>
Another possible solution is to give permits; in this case only to the reorganization exe (reor.exe).
For this, go to the link: "Increase Assembly Trust" and increase the level to “full trust” only in this assembly.<o:p> </o:p>
If it is necessary to assign different authorization levels to different web objects within the same virtual directory, the following steps must be taken.
Create a .aspx file per each web panel, web proc, etc. in the virtual directory. The file contents are not relevant; the only thing that matters is the fact that the file exists so that the ISS can verify the permits.
<o:p>Then, in the ISS, press the right button on the virtual directory / properties. In the area of application settings, go to the Configuration button. On the page “App mappings”, choose the aspx extension and go to the “Edit” button. Then, activate the check box: "check that file exists”.</o:p>