Create SQL users from within Navision
Pidi
Member Posts: 35
With 4.x (currently migrating) I love to touch every user three times instead of one time before ... :-(
Because of that I tried the following:
1. Storing all passwords in readable form in a seperate column within Tab13
2. Calling a stored procedure on the SQL Server from within Navision
3. passing username and pw with that sp_
4. Writing a TSQL script to call
Here´s the Navision code:
MakeSqlUser(InCodUsername : Code[10];InTxtPassword : Text[30])
HKchar := 39;
HK := FORMAT(HKchar);
CREATE(ADOConn);
REPEAT UNTIL VARIABLEACTIVE(ADOConn);
Serveradresse := 'yourserver';
Benutzername := 'sa';
passwort := 'yourpw';
OpenCMD := 'Provider=SQLOLEDB.1;Data Source=' + Serveradresse + ';' +
'User ID=' + Benutzername + ';Password=' + passwort + ';Initial Catalog=master';
ADOConn.Open(OpenCMD);
CREATE(ADOCmd);
REPEAT UNTIL VARIABLEACTIVE(ADOCmd);
ADOCmd.ActiveConnection(ADOConn.ConnectionString);
cmdLine := '{call master.dbo.bp_NewNavUser(' +HK +InCodUsername +HK +',' +HK +InTxtPassword +HK+')}';
ADOCmd.CommandText(cmdLine);
ADOCmd.CommandTimeout(20);
ADOCmd.CommandType(1);
ADOCmd.Execute;
ADOConn.Close;
CLEAR(ADOCmd);
CLEAR(ADOConn);
And the TSQL script stored in MASTER DB of the server:
CREATE PROCEDURE dbo.bp_NewBosUser
@loginname sysname,
@password varchar(30)
AS
IF (SELECT name FROM master.dbo.sysxlogins WHERE Name = @loginname) = @Loginname
BEGIN
exec bosfood.dbo.sp_revokedbaccess @loginname;
exec sp_droplogin @loginname;
END
exec sp_addlogin @loginname, @password
exec sp_defaultlanguage @loginname, N'Deutsch'
exec bosfood.dbo.sp_grantdbaccess @loginname, @loginname
exec bosfood.dbo.sp_addrolemember N'db_owner', @loginname
GO
And it does, what it´s supposed to do ...
The Navision code came from trial and error, the TSQL code was recorded with the Profiler.
I don´t have much experience with SQL server by now, and that´s the reason I´m looking for some feedback on this.
If anyone´s interested in the code (Nav object regarding the AC vars) send me an email.
Pidi
Because of that I tried the following:
1. Storing all passwords in readable form in a seperate column within Tab13
2. Calling a stored procedure on the SQL Server from within Navision
3. passing username and pw with that sp_
4. Writing a TSQL script to call
Here´s the Navision code:
MakeSqlUser(InCodUsername : Code[10];InTxtPassword : Text[30])
HKchar := 39;
HK := FORMAT(HKchar);
CREATE(ADOConn);
REPEAT UNTIL VARIABLEACTIVE(ADOConn);
Serveradresse := 'yourserver';
Benutzername := 'sa';
passwort := 'yourpw';
OpenCMD := 'Provider=SQLOLEDB.1;Data Source=' + Serveradresse + ';' +
'User ID=' + Benutzername + ';Password=' + passwort + ';Initial Catalog=master';
ADOConn.Open(OpenCMD);
CREATE(ADOCmd);
REPEAT UNTIL VARIABLEACTIVE(ADOCmd);
ADOCmd.ActiveConnection(ADOConn.ConnectionString);
cmdLine := '{call master.dbo.bp_NewNavUser(' +HK +InCodUsername +HK +',' +HK +InTxtPassword +HK+')}';
ADOCmd.CommandText(cmdLine);
ADOCmd.CommandTimeout(20);
ADOCmd.CommandType(1);
ADOCmd.Execute;
ADOConn.Close;
CLEAR(ADOCmd);
CLEAR(ADOConn);
And the TSQL script stored in MASTER DB of the server:
CREATE PROCEDURE dbo.bp_NewBosUser
@loginname sysname,
@password varchar(30)
AS
IF (SELECT name FROM master.dbo.sysxlogins WHERE Name = @loginname) = @Loginname
BEGIN
exec bosfood.dbo.sp_revokedbaccess @loginname;
exec sp_droplogin @loginname;
END
exec sp_addlogin @loginname, @password
exec sp_defaultlanguage @loginname, N'Deutsch'
exec bosfood.dbo.sp_grantdbaccess @loginname, @loginname
exec bosfood.dbo.sp_addrolemember N'db_owner', @loginname
GO
And it does, what it´s supposed to do ...
The Navision code came from trial and error, the TSQL code was recorded with the Profiler.
I don´t have much experience with SQL server by now, and that´s the reason I´m looking for some feedback on this.
If anyone´s interested in the code (Nav object regarding the AC vars) send me an email.
Pidi
Michael Peters
Bos Fod GmbH Düsseldorf
+49 2132 139-0
Bos Fod GmbH Düsseldorf
+49 2132 139-0
0
Comments
-
I've haven't tried it but, you should add it to tips and trick section.0
-
Hi,
How did you define the ADOConn variable in your code?? ](*,)
Which dll??
Thanxs!!!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 328 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
