BookmarkSubscribeRSS Feed
JNPLNCE
Calcite | Level 5

Hi All,

 

I am trying to access a Microsoft SQL Server Database from SAS using SQL Server Authentication. I have tried this syntax below with no luck. I was wondering if there is a different sytanx to use?

 

/* SQL Server Authentication reference: " https://support.sas.com/techsup/technote/ts765.pdf" */

LIBNAME SQL ODBC noprompt= "dsn=sqlsrv; uid=; pwd=; wsid=d17117";

 

 

 

Thanks!

JP

4 REPLIES 4
SASKiwi
PROC Star

Is your user account stored separately in SQL Server or are you authenticating with your OS account - usually called Windows Authentication if your SAS server runs on Windows? If it is the latter then something like this should work:

 

proc sql;
 connect to odbc (noprompt = "server=MyServerName;DRIVER=SQL Server;Trusted Connection=yes;");
  create table Want  as 
  select * from connection to odbc
  (SELECT *
   FROM [MyDatabase].[MySchema1].[MyTable]
   )
  ;
  disconnect from odbc;
quit;
JNPLNCE
Calcite | Level 5

My user account is stored separately in SQL Server. I've attached a screenshot of the sql log in. Thank you!

 

 


SQL_Server_Authentication.PNG
SASKiwi
PROC Star

If you still prefer to define everything in code and avoid the ODBC Adminstrator then this should work:

 

libname sqlsrvr odbc noprompt = "server=MyServerName;DRIVER=SQL Server;uid=myusr1;pwd=mypwd1;";

 

Reeza
Super User

Set it up in your DSN set up (Control Panel/ODBC Connections) rather than SAS and then use a 'plain' connection string.

 

I find this method easier to manage and then my password and uid are not stored in code anywhere.

 

LIBNAME SQL ODBC DSN=’myserver’ schema=dbo; 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1085 views
  • 0 likes
  • 3 in conversation