DB2OLEDB v5 and SQL Server 2016 - linked-server

I connect to an AS400 database using DB2OLEDB v5 as a linked server from SQL Server 2016--but Binary to Character will not translate. All binary fields on the AS400 database are returned as hex on the SQL Server. Has anyone had success using this type of linked server from SQL Server 2016? The provider string below is the same one I used successfully on SQL Server 2012. I really appreciate any help that can be provided. Here is my Provider string:
exec master.dbo.sp_addlinkedserver #server = N'JDE'
, #srvproduct = N'DB2OLEDB'
, #provider = N'DB2OLEDB'
, #datasrc = N'192.168.x.x'
, #provstr = N'Provider=DB2OLEDB;
User ID=########;
Password=########;
Initial Catalog=S06822B5;
Network Transport Library=TCPIP;
Host CCSID=37;
PC Code Page=1252;
Network Address=192.168.x.x;
Network Port=446;
Package Collection=QGPL;
Default Schema=CRDDTA;
Process Binary as Character=True;
Units of Work=RUW;
DBMS Platform=DB2/AS400;
Use Early Metadata=False;
Defer Prepare=False;
DateTime As Char=False;
Rowset Cache Size=0;
Datetime As Date=False;
AutoCommit=True;
Authentication=Server;
Decimal As Numeric=False;
Derive Parameters=True;
LoadBalancing=False;
Persist Security Info=False;
Cache Authentication=False;
Mode=Read;
Connection Pooling=False;'
, #catalog = N'S06822B5'
/* For security reasons the linked server remote logins password is changed with ######## */
and
exec master.dbo.sp_addlinkedsrvlogin #rmtsrvname = N'JDE'
, #useself = N'False'
, #locallogin = null
, #rmtuser = N'connect'
, #rmtpassword = '########'

Suggestion: for correct connection string and SQL server version use DB2OLEDBV6_x64.msi which part of SQL SERVER 2016 SP2 Feature Pack

Related

Connecting to Azure SQL database using DBI in R and ActiveDirectoryPassword authentication

I want to connect to AzureSQL database using DBI in R. I want to manage this connection via AzureAD ActiveDirectoryPassword authentication. This requires me to state the AzureAD UID and Password.
I have verified that I can connect to this server using other authentication methods.
Running the code below results in an error :
DBI::dbConnect(
odbc()
, Driver = "SQL Server"
, .connection_string =
sprintf("server=%s;database=dbName;UID=%s;PWD=%s;Authentication=%s;"
, 'sqlservername.database.windows.net'
, 'justin#contoso.com'
, pwd # Let's just assume this is securely done for now
, 'ActiveDirectoryPassword'))
Expected result was to connect to the database
Actual result was the following:
Error: nanodbc/nanodbc.cpp:950: HY000: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open server "contoso.com" requested by the login. The login failed.
I think the # in the username is not behaving in the way I initially expected that it might. How do I make this connection work? - I think I just need to find the correct format to express (escape?) the username.
This worked for me
DBI::dbConnect(
odbc()
, Driver = "SQL Server"
, .connection_string =
sprintf("server=%s;database=%s;UID=%s;PWD=%s;Authentication=%s;"
, 'sqlservername.database.windows.net'
, 'databasename'
, 'user#company.com'
, pwd # Let's just assume this is securely done for now
, 'ActiveDirectoryPassword'))

How to create a table in SQL Server with RevoScaleR?

I'd like to create a table in my SQL Server database running on a local instance and populate it with mine predicitve model written in R; to which aim I call these lines of R script:
predictionSql = RxSqlServerData(table = "Logit_FPD60_ZIP", connectionString = connStr)
predict_logit = rxPredict(logit_model, input_data, outData = predictionSql)
...which returns:
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user
'my server'.
I can establish a connection and preview data from the server.
I've tried:
Set SQL Server and Windows Authentication mode in my SQL Server
Security properties and restart both the service and Lunchpad.
Create a generic SQL Server Connector
which is:
[ODBC] DRIVER=SQL Server Native Client 11.0 DATABASE=Predict
WSID=NB-IT-JIRAK APP=Operační systém Microsoft® Windows®
Trusted_Connection=Yes SERVER=NB-IT-JIRAK\SJ Description=Generic SQL
Connector
I'm using this connection string in R:
connStr <- paste("Driver=SQL Server; Server=", "NB-IT-JIRAK\\SJ",
";Database=", "Predict", ";Trusted_Connection=true", sep = "");
What am I missing? New to R, help would be appreciated. Thanks in advance.
Change connection string to sa if it is a test machine or a use a privileged account:
connection_string <- sprintf("Driver=SQL Server;Server=%s;Database=%s;Uid=sa;Pwd=mypass", server, db_name)
commented: --> connection_string <- sprintf("Driver=SQL Server;Server=%s;Database=%s;Trusted_Connection=Yes", server, db_name)

Always Encrypted is not working for Where condition

I am using SQL Server 2016 to use always encryption option. I have 2 servers. I kept SQL Server 2016 in server and encrypted columns for my DB. I have hosted my ASP.NET MVC application on the other server using IIS. I am using Entity Framework to connect with SQL Server. I have added the column encryption setting=enabled; in my connection string.
I have also imported the certificate to the server in which my application hosted in IIS.
While running the below code, I am getting an error.
var userName= context.testtable.Where(p => p.email == "melody#gmail.com").FirstOrDefault();
Error
The data types varchar and varchar(100) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK_Auto1', column_encryption_key_database_name = 'testdb') collation_name = 'Latin1_General_BIN2' are incompatible in the equal to operator.

connecting to Oracle DB using Windows authentication / trusted connection in R

There are a lot of examples how to connect to an Oracle DB using password authentication (i.e. user id + password) in R. However, I need to figure out to set up the connection using Windows authentication / a trusted connection in R for an Oracle DB.
Example
I saw a similar case for a MySQL DB where a connection string is specified containing trusted_connection=true which, if I understand correctly, indicates Windows authentication / a trusted conenction.
library(RODBC)
dbhandle <- odbcDriverConnect('driver={SQL Server};server=servername\\\\instancename,port;database=testing;trusted_connection=true')
res <- sqlQuery(dbhandle, 'select * from information_schema.tables')
1) How exactly would that look like for Oracle DB using the information below?
Additional info (maybe useful):
In the tsnames.ora config file I added the following database address, which works using MS Access.
DBNAME.XXX.COM =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = DBNAME.XXX.COM)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = DBNAME.XXX.COM)
)
)

What's wrong with this ASP connection string?

I'm at the end of my rope on this. It should be so simple.
I just need to know what's wrong with this connection string:
dbc.open ("Driver={SQL Server}; Data Source = ServerName; Initial Catalog = InitialDB; " "User ID = Username; Password = Password;")
I get this error when running that line:
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I know ServerName is up and accepting connections, I know InitialDB exists, I know User ID and Password are valid for the database. What am I missing?
In notepad create file anyname.udl - let it be empty. After in explorer click it - you will get a dialog to create OLEDB connection string, select expected driver, and all connection param, ensure that "Allow saving password" = True. Press Ok.
Then again open file with notepad. Content is valid connection string
Try this...
dbc.open ("Provider=SQLOLEDB; Driver={SQL Server}; Data Source = ServerName; Initial Catalog = InitialDB; User ID = Username; Password = Password; Network Library=dbmssocn;")
As someone has already pointed out, udl is the best easiest way to create a conn string - here is a link that talks about it. https://web.archive.org/web/20210211044624/http://www.4guysfromrolla.com/webtech/070400-1.shtml
If you are using ADOdb you might want to try
"Provider=SQLNCLI10;Server=SERVER;Database=DATABASE;Uid=USERNAME;Pwd=PASSWORD"
for SQL Server 2008 Native Client or
"Provider=SQLNCLI;Server=SERVER;Database=DATABASE;Uid=USERNAME;Pwd=PASSWORD"
for SQL Server 2005 Native Client.
For ODBC, use
"Driver=SQL Server Native Client 10.0"
for SQL Server 2008 Native Client or
"Driver=SQL Native Client"
for SQL Server 2005 Native Client.
What's with the " " in the middle of the string?
Your connection string appears to be mixing ODBC and OLEDB. I would suggest visiting http://www.connectionstrings.com/ and finding the correct syntax for the desired provider.
Yours:
"Driver={SQL Server}; Data Source = ServerName; Initial Catalog = InitialDB; " "User ID = Username; Password = Password;"
ODBC:
"Driver={SQL Server};Server=ServerName;Database=InitialDB;Uid=Username;Pwd=Password;"
OLEDB:
"Provider=sqloledb;Data Source=ServerName;Initial Catalog=InitialDB;User Id=Username;Password=Password;"
Do you have visual studio?
Connect to the database server, and locate the database you want to connect to.
Right click, select properties. Your connection string to the db is right there.
Copy to wherever you want. -- Should be in web config, but you can paste it directly into code if you so desire.

Resources