In AX2012 I want to build an ODBC database connection to SQL Server 2008R2. Therefor I build the 32 Bit System-DSN ‘SQL Server Native Client 10.0’ (C:\Windows\SysWOW64\odbcad32.exe).
If I start the following code as job or directly in a button of a form, the connection to the database is correct.
{
LoginProperty loginProperty;
OdbcConnection myConnection1;
Statement myStatement;
SqlStatementExecutePermission perm;
str _query;
ResultSet result;
str retVal;
;
#macrolib.ocMegaBoard
loginProperty = new LoginProperty();
loginProperty.setDSN( #OCDSN );
myConnection1 = new OdbcConnection( loginProperty );
info('OK');
}
If I start the same code as part of different procedure calls, the following error message is coming:
‘[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application‘
Please, can you help me?
Similar problems have been reported elsewhere.
Most likely your code works when executed by the client (32-bit), but fails when executed on the server AOS (64-bit). Just be sure to define your DSN on your AOS server as well, here as 64-bit.
Related
I am creating an ODBC connection to Import data from SQL (SSMS) to D365FO.
I have created a Test database and created an ODBC Data Source for it (DSN: TestDS, Server: local, Default database: TestDB).
Running SQL Server ODBC Data Source Test works fine:
Running connectivity tests...
Attempting connection
Connection established
Verifying option settings
Disconnecting from server
TESTS COMPLETED SUCCESSFULLY!
The Server Browser is running, class runOn server is set.
Here is a piece of my code:
public server static void main(Args _args)
{
OdbcConnection con;
LoginProperty loginProp;
loginProp = new LoginProperty();
loginProp.setDSN("TestDS");
con = new OdbcConnection(loginProp);
}
In the debugging window it throws me the following error:
"Object 'OdbcConnection' could not be created"
On the user side I am getting the following errors:
"ODBC operation failed. Unable to log on to the database."
"Unable to retrieve message for retval -1, ODBC call reason code -2, SQLSTATE = []"
As I know, ODBC for data import hasn't been yet supported in 2016. Is it supported now? I have found the exactly similar standard AX7 code, but I am not able to test if it works in standard.
Anybody had something similar to this and got it solved?
Running into a odd error when trying to move a SQL connection details from R code to the DSN and using the DSN as the connection string.
Using the ODBC package, I can build a connection through RStudio using:
con <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server Native Client 11.0",
Server = "XXX",
Database = "YYY",
uid = "username",
pwd = "password",
port = 1443)
This code above works correctly and allows the SQL connection. When moving this to the DSN (have attempted both user and system DSN) an error is generated. Both user and system DSN's have been tried and when connections are tested from the ODBC application in Windows (Win 10), the test is successful.
When using the code below in R, the connection fails.
con <- DBI::dbConnect(odbc::odbc(), "ZZZ")
Error: nanodbc/nanodbc.cpp:950: 28000: [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user ''
This would seem to indicate that the username is unknown but my information is that all of the connection parameters are stored in the DSN entry. My initial setup was generated from:
https://support.rstudio.com/hc/en-us/articles/214510788-Setting-up-R-to-connect-to-SQL-Server-
Following the further discussion at the bottom of the page, only appears to discuss the code version of the connection.
https://db.rstudio.com/databases/microsoft-sql-server/
This link discusses the DSN component as well as ensuring the driver is available.
https://db.rstudio.com/getting-started/connect-to-database
This confirms the code structure when trying to use the DSN.
I also verified this code snippet via:
https://www.r-bloggers.com/setting-up-an-odbc-connection-with-ms-sql-server-on-windows/
I attempted to use the SQL Server Driver versus the Native Client version and received the same error except the ODBC SQL Server Driver identifier instead of the Native Client 11.0. This seems to indicate that the dbconnect call is at least identifying the DSN entry.
Using the code below I confirmed that the Driver for both SQL Server and native Client 11.0 were available.
sort(unique(odbcListDrivers()[[1]]))
Add trusted connection attribute
con <- DBI::dbConnect(odbc::odbc(),
Driver = "SQL Server Native Client 11.0",
Server = "XXX",
Database = "YYY",
Trusted_Connection = "True",
uid = "username",
pwd = "password",
port = 1443)
Not sure if you're encountering the same issue, but the credentials used during DSN creation (Windows account) were different from those used in the dbConnect function call (somehow, my Microsoft account).
The user in the error message did not exist in the Security roles within SQL Server, thus not granting access to connect to the database.
Granting the user in the error message access to the required SQL server/database fixed the issue*.
CREATE LOGIN [MicrosoftAccount\xyz#outlook.com] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]
ALTER SERVER ROLE [sysadmin] ADD MEMBER [MicrosoftAccount\xyz#outlook.com]
* though additional security measures are advised in role creation, off-topic here.
I have problems with an ODBC connection used in a batch job: when executed, I have the following error message :
"The ODBC operation failed.Unable to connect to database
Invalid connection String attribute Trusted_Connection
Unabe to create object 'OdbcConnection' "
I try to connect to an Access database, I use the following code:
LoginProperty loginProperty;
OdbcConnection odbcConnection;
;
loginProperty = new LoginProperty();
loginProperty.setDSN("MyDSN");
loginProperty.setDatabase("MyDatabase");
odbcConnection = new OdbcConnection(loginProperty);
when debugging, it crashes on odbcConnection = new OdbcConnection(loginProperty). I tested the same code in a job in local client execution, there was no problem and it worked fine(without defining login password in code or DSN). My DSN seems to be OK on AOS, I'm using AX 2009 without SP1, I saw some examples where there was login/password defined in loginProperty object , the setUserName() and setPassword() methods are not available in my AX version loginProperty object. My class is executed on server-side (as any batch job).
Is there some particular setup to do to connect to ODBC datasource through batch job?
any ideas or suggestions?
thanks for your help
Edit:AOS is running on Windows server 2003 32 bits, ODBC tested on it, works fine but doesn't work in AX through batch job
Most likely you will need a 32-bit DSN connection for your AX. I would create both versions on the AOS server.
Look here for details.
It may be caused due to permisions. "trusted connection" refers to the fact that you connect to the database through the user logged to the current session. When you run a Job from the AX client, this is executed with the user that runs the current AX client (the one logged to the active session); When code is executed from server in a batch job, code is executed through the user that runs the AOS windows service.
Has this user permissions to read/write/access the access file and directory?
If you are on a 64 bit machine use C:\Windows\SysWOW64\odbca32.exe to create the datasource.
Check under which ID the AOS runs, log on with that ID and make sure you can 'see' the data source.
Also make sure that the AOS account has access to the directory/files (if using file-based odbc)
I'm having a strange problem with IIS, asp.net and ODBC.
My application is driven by SQL server via ODBC driver (I know it's bad practice, but my entire DAL is already written and will not be changed).
The problem is that when I run an SP with my web interface, on any other computer other than the production server it works fine, but on the production server I get the following error:
Exception Message: System.Data.Odbc.OdbcException (0x80131937): ERROR [42000] [Microsoft] [ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to int
Obviously when I run it under management studio it works fine.
I think the problem is somewhere between the IIS and the odbc driver, but I'm not sure exactly where.
I'm running .net framework 4.
This is the calling method:
ODBCComm command = new ODBCComm();
command.Query = "SP_web_update_calls_dest #id=?,#name=? ,#ivrCode=?,#DDI=?,#destType=?,#trkGroup=?,#result=? output";
command.AddInputParam(id);
return AddParamsAndExecute(name, ivrCode, DDI, destType, trkGroup, command);
it basically wraps arround:
OdbcCommand.ExecuteDirect();
Thanks a lot,
Yuval.
I believe your first param is being used in the ID spot. I'm not sure why this would work in pre-production and fail only in production, but try this instead...
ODBCComm command = new ODBCComm();
command.Query = "SP_web_update_calls_dest #id=?,#name=? ,#ivrCode=?,#DDI=?,#destType=?,#trkGroup=?,#result=? output";
return AddParamsAndExecute(id, name, ivrCode, DDI, destType, trkGroup, command);
I have no idea what ODBCComm is or what AddParamsAndExecute does because you haven't included the relavant code, however, here's what the request should look like:
OdbcCommand Cmd = new OdbcCommand("SP_web_update_calls_dest", _Connection);
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.Add("#id", OdbcType.Int);
Cmd.Parameters["#id"].Value = id;
Cmd.Parameters.Add("#name", OdbcType.NVarChar);
Cmd.Parameters["#name"].Value = name;
Cmd.Parameters.Add("#ivrCode", OdbcType.Int);
Cmd.Parameters["#ivrCode"].Value = ivrCode;
Cmd.Parameters.Add("#DDI", OdbcType.VarChar);
Cmd.Parameters["#DDI"].Value = DDI;
Cmd.Parameters.Add("#destType", OdbcType.Int);
Cmd.Parameters["#destType"].Value = destType;
Cmd.Parameters.Add("#trkGroup", OdbcType.Int);
Cmd.Parameters["#trkGroup"].Value = trkGroup;
Cmd.Parameters.Add("#result", OdbcType.Int);
Cmd.Parameters["#result"].Direction = ParameterDirection.Output;
Cmd.ExecuteNonQuery();
int result = (int)Cmd.Parameters["#result"].Value;
OK,
I think I solved it.
There were actually 2 problems, and I'm not exactly sure what caused them.
Anyway, I switched the ODBC driver to SQL Server Native Client 10.
This basically solved the problem, but for some reason it doesn't support the output modifier in queries so I had to remove that.
So I got it solved, but still have no idea what caused the problem. I'm guessing it has something to do with different versions of drivers.
I'm writing a small ASP.NET application in a hosted environment (meaning I don't own the server).
Using the hosting provider's webtools, I created a DSN that specifies the Driver, the Server, the UID, the PWD, and the Database. When I test the connection, it tests out fine.
However, when I load my web page with the code:
OdbcConnection DB = new OdbcConnection("DSN=MyDSNName");
DB.Open();
I get the error: ERROR [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user ''.
I know I'm using the correct DSN name because when I change to "DSN=NonExistentDSN" I get a different error.
I don't understand why the logon works when I test it but not when I use it in code. Since I don't own the server, some of the usual troubleshooting tools aren't available to me, but I'd appreciate any feedback the community has.
Perhaps the DSN does not retain the password. Have you tried to supply login credentials?
OdbcConnection DB = new OdbcConnection("DSN=MyDSNName;UID=login;PWD=password;");
DB.Open();