SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ZLX
Fluorite | Level 6 ZLX
Fluorite | Level 6

I am try to connect to MySQL database on remote server by using ODBC. I don't know whether the statement is wrong or something else because the log shows a lot of garbled characters. The SAS EG server system encode has been set to utf-8 already and the system language is Chinese.

屏幕截图 2022-03-07 100334.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Database connection strings are notoriously tricky. They are sensitive to spaces, line feeds, lower and uppercase and so on. I doubt it will work the way you have it spread over several lines. This is what a working ODBC connection to SQL Server looks like:

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

Has the correct ODBC driver been installed on the SAS App server? Check with your SAS administrator for the right set up.

 

Regarding the garbled characters. This is most likely caused by differing encoding / language settings in SAS versus MySQL. Getting help from SAS Tech Support is a good idea.

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star

Database connection strings are notoriously tricky. They are sensitive to spaces, line feeds, lower and uppercase and so on. I doubt it will work the way you have it spread over several lines. This is what a working ODBC connection to SQL Server looks like:

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

Has the correct ODBC driver been installed on the SAS App server? Check with your SAS administrator for the right set up.

 

Regarding the garbled characters. This is most likely caused by differing encoding / language settings in SAS versus MySQL. Getting help from SAS Tech Support is a good idea.

ZLX
Fluorite | Level 6 ZLX
Fluorite | Level 6

Thanks for your remarkable prompt, which "Database connection strings are notoriously tricky. They are sensitive to spaces" inspires me quite a lot!

 

The driver name after DRIVER= option must not be with a leading space! It is my personal habit to type spaces between the euqal sign, which confused me pretty much when facing this scenario. I must watch out for this careully thereafter.

 

I also found that the value of DATABASE= option is the schema name, to which waited to connect. The MySQL database structure should be distinguished from MS SQL Server.

 

Thanks for your help again!!!!!!!!!

 

#Failed - with leading space
libname mysqldb odbc noprompt = "driver = MySQL ODBC 8.0 Unicode Driver;server=xxx;port=xxx;uid=xxx;pwd=xxx;database=xxx"; 

#Successful - without leading space
libname mysqldb odbc noprompt = "driver=MySQL ODBC 8.0 Unicode Driver;server=xxx;port=xxx;uid=xxx;pwd=xxx;database=xxx"; 

 

 

SASKiwi
PROC Star

@ZLX - I should have mentioned this very useful website: ConnectionStrings.com - Forgot that connection string? Get it here!

 

Yes, leaving out spaces is a very good idea when testing connection strings.

ZLX
Fluorite | Level 6 ZLX
Fluorite | Level 6
Nice!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 4 replies
  • 1744 views
  • 2 likes
  • 2 in conversation