1

I'm trying to configure a MariaDB ODBC DSN automatically in PowerShell

my code so far is this:

$DriverName = (Get-OdbcDriver -Name "MariaDB*" | Where-Object Platform -eq "64-bit").Name# Setting up $dsn, $server, $port, $user, $pwd and $db$Properties = @("SERVER=$server", "PORT=$port", "USER=$user", "PASSWORD=$pwd", "DATABASE=$db")Add-OdbcDsn -Name $DSNName -DriverName $DriverName -DsnType "User" -Platform "64-bit" -SetPropertyValue $Properties

I keep getting the error

Add-OdbcDsn : Driver's ConfigDSN, ConfigDriver, or ConfigTranslator failed (Installer error code: 11).+     Add-OdbcDsn -Name $DSNName -DriverName $DriverName -DsnType "User ...+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotSpecified: (... ODBC User DSN):Root/Microsoft/...SFT_OdbcDsnTask) [Add   -OdbcDsn], CimException    + FullyQualifiedErrorId : MI RESULT 0,Add-OdbcDsn

It seems to be some missing field in $properties, but I can't figure out which one I'm missing

Thanks

Edit to add: I'm using the ODBC driver MariaDB ODBC 3.1 Driver, on windows 11

Edit #2: I made sure that $DriverName gives me only one value.

Also, as someone mentionned, I tried adding the option UID=$user and PWD=$pwd but it gave me the error

Add-OdbcDsn : Attempt to set the {UID or PWD} key of a DSN. These keys should not be stored in the registry for security reason. Provide the credential information at runtime via SQLDriverConnect, SQLConnect or SQLBrowseConnect.
askedJul 25 at 15:29
gee3107's user avatar
10
  • Thedocumentation appears to suggest you need to include"Driver={MariaDB ODBC 3.1 Driver}" (or perhaps explicitly pass that as the DriverName argument)CommentedJul 25 at 16:55
  • 1
    @MathiasR.Jessen isn't it what the option -DriverName $DriverName do ?CommentedJul 25 at 20:08
  • You only need to use Add-OdbcDsn once on a machine or manually add the entry into the computer. From start button type : ODBC Data Source. See if odbc is already added to you machine.CommentedJul 25 at 21:21
  • 1
    @jdweng Yes I know how to use ODBC Data Sources. I wan to do it in a script because I will need to give that script to people without needing them to manually configure itCommentedJul 26 at 0:33
  • 1
    @gee3107 yes, but we don't know how many versions of the driver is installed on the machine - you may be passing the name of multiple driversCommentedJul 26 at 9:47

0

Know someone who can answer? Share a link to thisquestion viaemail,Twitter, orFacebook.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.