Which Codeunit Calls when Open a Database

lakshman
Member Posts: 44
Hi Experts,
My Requirement is To restrict to open a database if the database is already open with same userid. so that i want to know which codeunit calls when open a database.
(not a open company. when open company codeunit 1 called).please suggest me.
Thanks & Regards
lakshman
My Requirement is To restrict to open a database if the database is already open with same userid. so that i want to know which codeunit calls when open a database.
(not a open company. when open company codeunit 1 called).please suggest me.
Thanks & Regards
lakshman
0
Comments
-
lakshman wrote:Hi Experts,
My Requirement is To restrict to open a database if the database is already open with same userid. so that i want to know which codeunit calls when open a database.
(not a open company. when open company codeunit 1 called).please suggest me.
Thanks & Regards
lakshman
It is old catch no trigger exists on database open (I tested with debugger, first trigger is CompanyOpen in CU1 after company choice). IF SQL server option used, you can run following stored procedure trigged by SQL server agent.CREATE PROCEDURE KillGluttonUsers AS DECLARE @Victim INTEGER DECLARE @SQLCommand VARCHAR(30) DECLARE _ToKill CURSOR LOCAL FAST_FORWARD FOR SELECT [Connection ID] FROM Session INNER JOIN ( SELECT s.*, (SELECT TOP 1 [Connection ID] FROM Session WHERE s.[User ID] = Session.[User ID] ORDER BY [Login Time]) AS FirstConnectionID FROM ( SELECT COUNT(*) AS NoOfConnections, [User ID] FROM Session WHERE [Application Name] = 'Microsoft Business Solutions-Navision client' AND [Database Name] = db_name() GROUP BY [User ID] HAVING COUNT(*) > 1 ) s ) k ON Session.[User ID] = k.[User ID] AND Session.[Connection ID] <> k.FirstConnectionID WHERE [Application Name] = 'Microsoft Business Solutions-Navision client' AND [Database Name] = db_name() OPEN _ToKill FETCH NEXT FROM _ToKill INTO @Victim WHILE @@FETCH_STATUS = 0 BEGIN SET @SQLCommand = 'KILL ' + CAST(@Victim AS VARCHAR) EXEC (@SQLCommand) FETCH NEXT FROM _ToKill INTO @Victim END CLOSE _ToKill DEALLOCATE _ToKIll
_-========-_
GreenSmile0 -
search also the forum for this.There are also examples if u are under native (CU1) or sql (Procedure to kill the session directly on sql server engin)
RegardsDo you make it right, it works too!0 -
Another approach on SQL is to create the stored procedure [$ndo$loginproc] in the database.
You can put any logic you want in here (it should not return result sets though) and it should have execute permissions granted to public.
NAV will execute this proc on database open (if it exists) and will disallow the connection if the proc raises an error message with RAISEERROR.
For example, you can check if there is a connection already using the current user ID as you mentioned, similar to the code shown in the previous post, and if so raise an error disallowing the new connection. This proc is documented I think in the Application Designers guide, although I cannot check that right now.
[You can also use this proc to have a message sent to NAV, which is displayed for information only in a dialog box, but allows the connection to continue. E.g. "System down for maintencance at 09:00"].Dean McCrae - Senior Software Developer, NAV Server & Tools
This posting is provided "AS IS" with no warranties, and confers no rights.0 -
@dmccrae: Are there some other $ndo$ Procedures / Tables which are checked by NAV ( [not] documented features) ?
Here a link for all for $ndo$loginproc http://msdn.microsoft.com/en-us/library/dd338930.aspx
it's also explained in the Application Designer's Guide
RegardsDo you make it right, it works too!0 -
The examples in your MSDN link are those I had originally prepared and outlined in the ADG, to demonstrate the use of the PRINT and RAISEERROR scenarios. There are no other built-in procs like this; the only other similar concept is the [$ndo$dbconfig] table, which is pretty well known now for influencing index hint behaviour and so on.
If you look at a SQL Profiler trace you will see the (attempted) execution of the login proc when connecting.
Important: If you use this proc and grant execute permission to public, you are of course allowing all users to run it. That's not an issue if its only purpose is disallowing a connection, or showing a warning in the client - but any activity on the database should be avoided, or treated with caution.Dean McCrae - Senior Software Developer, NAV Server & Tools
This posting is provided "AS IS" with no warranties, and confers no rights.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions