BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
monona
Obsidian | Level 7

I am trying to connect to MS SQL server 2014. I found that I need odbc connection. So I tried to set this up, but faced this kind of problem. image_2.1.PNG

 

My windows account is entirely authorized for the database at the moment, but still not working. 

  • I want to figure out how to resolve this.
  • I would glad to hear if there is another way to connect SAS to MS sql server.
1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

If you prefer not doing DSNs you can do the complete connection string in SAS like so:

 

libname SQLSRVR odbc noprompt = "server=SQLServerName;DRIVER=SQL Server Native Client 11.0;Trusted Connection=yes" DATABASE = MyDatabase schema = dbo;

This is what we do as it avoids having to maintain DSNs entirely.

View solution in original post

21 REPLIES 21
Reeza
Super User

That's not a SAS issue, that's something you need to talk to your IT team. Once you have the DSN set up on your computer, then getting access within SAS is relatively easy. 

 

libname myData odbc dsn=dsnName schema=dbo;

Perhaps your DB doesn't allow for single sign on, did you try signing in manually?

 


@monona wrote:

I am trying to connect to MS SQL server 2014. I found that I need odbc connection. So I tried to set this up, but faced this kind of problem. image_2.1.PNG

 

My windows account is entirely authorized for the database at the moment, but still not working. 

  • I want to figure out how to resolve this.
  • I would glad to hear if there is another way to connect SAS to MS sql server.

 

monona
Obsidian | Level 7
Where can I obtain dsnName? Where can I access?
Reeza
Super User

When you set up the DSN, in the screenshot shown, you set the DSN name there. 

You have to fix that error you're showing first, however, that's not something the forum can help you out with, its dependent on your set up and permissions which you really shouldn't share with us. 

 


@monona wrote:
Where can I obtain dsnName? Where can I access?

 

SASKiwi
PROC Star

If you prefer not doing DSNs you can do the complete connection string in SAS like so:

 

libname SQLSRVR odbc noprompt = "server=SQLServerName;DRIVER=SQL Server Native Client 11.0;Trusted Connection=yes" DATABASE = MyDatabase schema = dbo;

This is what we do as it avoids having to maintain DSNs entirely.

ScottBass
Rhodochrosite | Level 12

Further to @SASKiwi 's comment, I have written a macro to assist me at my client since I work with SQL Server all the time.

 

Perhaps you may find this useful, or at least can use it as a starting point.  Obviously you may need to edit it for your site specific requirements.

 

https://github.com/scottbass/SAS/blob/master/Macro/libname_sqlsvr.sas


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
monona
Obsidian | Level 7
Thanks for your reply! I got error messages though.

ERROR: CLI error trying to establish connection: [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for
user ''. : [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute
ERROR: Error in the LIBNAME statement.
SASKiwi
PROC Star

Can you post your LIBNAME statement please. The connection strings are fiddly to get right. For example blanks matter.

monona
Obsidian | Level 7
Here!

libname abc odbc noprompt = "server=XXX;DRIVER=SQL Server Native Client 11.0;Trusted Connection=yes" DATABASE = XXX schema = dbo;
SASKiwi
PROC Star

Sorry, my bad. Try this (added underscore):

Trusted_Connection=yes;

or

libname abc odbc noprompt = "server=XXX;DRIVER=SQL Server Native Client 11.0;Trusted_Connection=yes" DATABASE = XXX schema = dbo;

 

monona
Obsidian | Level 7

OMG!!!! I LOVE YOU. IT WORKS!!!

SASKiwi
PROC Star

@monona -I'm pleased you like this solution. I reckon it's pretty cool too yet it is not a well known way of connecting to relational databases. 

ScottBass
Rhodochrosite | Level 12

@monona wrote:

OMG!!!! I LOVE YOU. IT WORKS!!!


 

Congratulations @SASKiwi !!! 😄


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
monona
Obsidian | Level 7
One last question....!
I actually create the library like that, but it doesn't show up in the database on ms sql server studio. do you know where the library i create on sas is stored?
SASKiwi
PROC Star

It won't show up there, it is purely a SAS thing. It will appear in your SAS Enterprise Guide server list or the library list in SAS Studio or the SAS Windowing Environment.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 21 replies
  • 29603 views
  • 7 likes
  • 6 in conversation