Usage of DBExecutor.ExecuteReader is denied by application security settings.

Hello i need to Access data directly.
https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…

I am Using Select class to retrive data andI am getting error: Usage of DBExecutor.ExecuteReader is denied by application security settings.

Like 0

Like

6 comments

Hi Tomasz,

Could you please send an example of the implementation you've done and on which version of Creatio you encountered this message?

Serhii Parfentiev,

    var selectQuery = new Select(UserConnection)
                                .Column("Account", "Name")
                                .From("Account")
                                .Where("Account", "PakietNIP").IsEqual(Column.Const(nip));
                                
    using (DBExecutor dbExec = UserConnection.EnsureDBConnection()) {
        using (IDataReader reader = dbExec.ExecuteReader(selectQuery.GetSqlText())) {
            while (reader.Read()) {
                var name = reader.GetColumnValue<string>("Name");
              throw new Exception("Istnieje już firma o podanym NIP: '" + nip + "' i nazwie: " + name);               
            }
        }
    }


8.2.3.1351
    var selectQuery = new Select(UserConnection)
                                .Column("Account", "Name")
                                .From("Account")
                                .Where("Account", "PakietNIP").IsEqual(Column.Const(nip));
                                
    using (DBExecutor dbExec = UserConnection.EnsureDBConnection()) {
        using (IDataReader reader = dbExec.ExecuteReader(selectQuery.GetSqlText())) {
            while (reader.Read()) {
                var name = reader.GetColumnValue<string>("Name");
              throw new Exception("Istnieje już firma o podanym NIP: '" + nip + "' i nazwie: " + name);               
            }
        }
    }


8.2.3.1351
 

Tomasz Sobkowicz,

DBExecutor was deprecated a while back IIRC. From what I remember it was left as stubbed out functions to not break existing code or something like that.

Try using it with something like this: 

var selectQuery = new Select(UserConnection)
    .Column("Account", "Name")
    .From("Account")
    .Where("Account", "PakietNIP").IsEqual(Column.Const(nip));
 
selectQuery.ExecuteReader(reader =&gt; {
    do 
    {
        var name = reader.GetColumnValue&lt;string&gt;("Name");
        // do something...
    }
    while (reader.Read());
});

Basically, call ExecuteReader on the Select, instead of calling it on the DBExecutor and passing it the select's SQL text. 

Or with this approach, still using the DBExecutor, even though it's not really doing anything

var selectQuery = new Select(UserConnection)
    .Column("Account", "Name")
    .From("Account")
    .Where("Account", "PakietNIP").IsEqual(Column.Const(nip));
 
using (DBExecutor dbExecutor = UserConnection.EnsureDBConnection()) {
	using (IDataReader reader = selectQuery.ExecuteReader(dbExecutor)) {
		while (reader.Read()) {
			var name = reader.GetColumnValue&lt;string&gt;("Name");
        	// do something...
		}
	}
}

Ryan

Ryan Farley,

Are you sure DBExecutor is deprecated? The link Tomasz provided in the original post is for 8.x, and at the bottom of the article shows a query that is basically identical to Tomasz' shared code. EDIT: ah, I see the difference now - it's mainly the line:

using (IDataReader reader = dbExecutor.ExecuteReader(selectQuery.GetSqlText())) {

in Tomasz' example, vs:

using (IDataReader reader = selectQuery.ExecuteReader(dbExecutor)) {

in your example; so running ExecuteReader from the Select object rather than the DBExecutor object.

Interestingly, that article also states that CustomQuery is deprecated and will be removed soon too, which is a little concerning - I know you've previously said that your understanding is that it will not be getting removed any time soon, but maybe that's changed which would be unfortunate with seemingly no alternative.

Harvey Adcock,

Technically, they were deprecated and marked for removal in version 7.17.4, however, I don't know that they were ever officially marked as deprecated in the DLLs. See 7.17.4 release notes: https://academy.creatio.com/docs/8.x/resources/release-notes/7174-release-notes#title-1976-9

I opened a case at that time (SR-0977033). I was told that all DBExecutor would be removed as well as the use of CustomQuery and using those would produce an error (which would make any ode that executes a custom SQL statement no longer work as well). However, after discussion about the need for this to remain a part of Creatio, that was walked back (thankfully! hopefullly that never changes, it would be a crippling change). I got the impression that the purpose for DBExecutor was removed, but the methods left to avoid breaking existing code. 

Harvey Adcock,

Right. The difference being in Tomasz' code, DBExecutor is calling ExecuteReader. That just needs to be moved so it's called from the Select object, not DBExecutor.

Show all comments