Problems with ADO after upgrade to NAV 2017 / SQL 2014

lzr
Member Posts: 264
in SQL General
Hi all,
Recently did a test upgrade to SQL 2014 and NAV 2017 and now our encryption function doesn't work anymore. The same function runs perfectly in NAV 2009 classic on SQL 2008. I used Rasheds code example a long time ago ( https://community.dynamics.com/nav/b/navrashedamini/archive/2009/05/20/encrypting-data-in-nav-using-sql-with-ado)
I think the error message is this "Item cannot be found in the collection corresponding to the requested name or ordinal", it's in Swedish so I am not sure.
If I run the code in SQL Management studio 2014 using the same user it executes properly. It looks like the ADO is not returning any data
The SQL code which works:
The code in NAV 2017 which doesn't work:
Would really appreciate if someone can point me in the right direction. If I can't get this to work I guess I have to export all old data and encrypt it with some other function.
Recently did a test upgrade to SQL 2014 and NAV 2017 and now our encryption function doesn't work anymore. The same function runs perfectly in NAV 2009 classic on SQL 2008. I used Rasheds code example a long time ago ( https://community.dynamics.com/nav/b/navrashedamini/archive/2009/05/20/encrypting-data-in-nav-using-sql-with-ado)
I think the error message is this "Item cannot be found in the collection corresponding to the requested name or ordinal", it's in Swedish so I am not sure.
If I run the code in SQL Management studio 2014 using the same user it executes properly. It looks like the ADO is not returning any data
The SQL code which works:
OPEN MASTER KEY DECRYPTION BY PASSWORD = 'blabla' ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY CLOSE MASTER KEY OPEN SYMMETRIC KEY TestTableKey DECRYPTION BY CERTIFICATE EncryptTestCert declare @hexbin varbinary(max); set @hexbin = ENCRYPTBYKEY(KEY_GUID('TestTableKey'),N'1111'); CLOSE SYMMETRIC KEY TestTableKey select '0x' + cast('' as xml).value('xs:hexBinary(sql:variable("@hexbin") )', 'varchar(1024)') as Column1;
The code in NAV 2017 which doesn't work:
ConnectionString:='Driver={SQL Server};' + 'Server=bella;' + 'Database=nav;' + 'User ID=decrypter;' + 'Password=1234;'; IF ISCLEAR(lADOConnection) THEN CREATE(lADOConnection, FALSE, TRUE); lADOConnection.ConnectionString(ConnectionString); lADOConnection.Open; IF ISCLEAR(lADOCommand) THEN CREATE(lADOCommand, FALSE, TRUE); lvarActiveConnection := lADOConnection; lADOCommand.ActiveConnection := lvarActiveConnection; IF ISCLEAR(lADORecordset) THEN CREATE(lADORecordset, FALSE, TRUE); lADORecordset.ActiveConnection := lvarActiveConnection; SqlCommand := 'OPEN MASTER KEY DECRYPTION BY PASSWORD = ''blabla'' ' + 'ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY ' + 'CLOSE MASTER KEY '; lADOCommand.CommandText := SqlCommand; lADOCommand.CommandTimeout := 0; lADOCommand.Execute; SqlCommand := 'OPEN SYMMETRIC KEY TestTableKey DECRYPTION BY CERTIFICATE EncryptTestCert ' + 'declare @hexbin varbinary(max); ' + 'set @hexbin = ENCRYPTBYKEY(KEY_GUID(''TestTableKey''),N''1111''); '+ 'select ''0x'' + cast('''' as xml).value(''xs:hexBinary(sql:variable("@hexbin") )'', ''varchar(1024)'') as Column1;' + 'CLOSE SYMMETRIC KEY TestTableKey '; lADOCommand.CommandText := SqlCommand; lADOCommand.CommandTimeout := 0; lADOCommand.Execute; lADORecordset.Open('SET NOCOUNT ON'); lADORecordset.Open(lADOCommand); Value := lADORecordset.Fields.Item('Column1').Value; lADORecordset.Close; lADOConnection.Close; CLEAR(lADOConnection);
Would really appreciate if someone can point me in the right direction. If I can't get this to work I guess I have to export all old data and encrypt it with some other function.
Navision developer
0
Best Answer
-
you could try and rewrite this code to use ado .net, or maybe even better, start using the encryption functions NAV has now.5
Answers
-
you could try and rewrite this code to use ado .net, or maybe even better, start using the encryption functions NAV has now.5
-
I agree. Either use dotnet type. There are many examples on using ADO with dotnet. Or use the new encryption mechanism NAV has built. There are several limitation to nav encryption. Such as length of the field.0
-
Thanks for your answers!
I rewrote the code using ADO.NET and it worked.Navision developer0 -
Hi
I'm doing some of the same code, but I have trouble connecting to sql - on the SQLConnection.OPEN (it says "...network path not found").
I run NAV 2016
Thois is my connection sstring with dotnet
My connection string looks like this:
ConnectionString :='Data Source=mssql.xxxxx.dk;Initial Catalog=xxxxxxx;User Id=xxxx;Password=xxxxxxx';
The error appears in the
SQLConnection := SQLConnection.SqlConnection(ConnectionString);
SQLConnection.Open;
Hope to hear from you0
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