cancel
Showing results for 
Search instead for 
Did you mean: 

User ID 'SQLAnywhere' does not exist

0 Kudos
3,709

I'm using SAP's SQLAnywhere 17 .NET library to connect to a database (in PowerShell), but can't find anything on the internet for the connection string format.

My credentials are as follows:

Host: 10.10.10.10:12345 Server: testserver UID: DBA Password: 123 Database: testdb

This string does not work; gives me "The user 'SQL Anywhere' does not exist."

Host=10.10.10.10:12345;Server=testserver;DatabaseName=testdb;UserID=DBA;Password=123

This string generated by SQL Central does not work; gives me "The user 'SQL Anywhere' does not exist."

UID=DBA;PWD=123;Server=testserver;dbn=testdb;ASTART=No;host=10.10.10.10:12345

This is the stack trace generated by .NET:

 Sap.Data.SQLAnywhere.SAException (0x80004005): User ID 'SQLAnywhere' does not exist
   at Sap.Data.SQLAnywhere.SACommand._ExecuteReader(CommandBehavior commandBehavior, Boolean isExecuteScalar, Boolean isBeginExecuteReader)
   at Sap.Data.SQLAnywhere.SACommand.ExecuteReader()
   at Sap.Data.SQLAnywhere.SADataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   at CallSite.Target(Closure , CallSite , Object , Object )

Accepted Solutions (1)

Accepted Solutions (1)

jack_schueler
Product and Topic Expert
Product and Topic Expert

Your original code looked something like this ...

[Sap.Data.SQLAnywhere.SACommand] $saCommand = New-Object Sap.Data.SQLAnywhere.SACommand($command, $conn)
[Sap.Data.SQLAnywhere.SAParameter] $parameter = New-Object Sap.Data.SQLAnywhere.SAParameter("", $variable)
[void] $saCommand.Parameters.Add($parameter)
[System.Data.DataSet] $dataset = New-Object System.Data.DataSet
[Sap.Data.SQLAnywhere.SADataAdapter] $adapter = New-Object Sap.Data.SQLAnywhere.SADataAdapter($saCommand, $conn)

There is no SADataAdapter overload that takes a command and connection object, but there is a best fit for string and connection object. So PowerShell converted your $saCommand object to the string form of the object type (Sap.Data.SQLAnywhere.SACommand) and that string is executed on the server as "CALL Sap.Data.SQLAnywhere.SACommand()". The owner name is SQLAnywhere. That user ID does not exist.

You really want the SADataAdapter(SACommand) overload. The corrected code should read as follows:

[Sap.Data.SQLAnywhere.SADataAdapter] $adapter = New-Object Sap.Data.SQLAnywhere.SADataAdapter($saCommand)

To see the effect that you were getting try this: Write-Output "$saCommand"

Answers (1)

Answers (1)

jack_schueler
Product and Topic Expert
Product and Topic Expert

A PowerShell debugging tip. Write your exception handler like this.

} catch {
    $e = $_.Exception
    $line = $_.InvocationInfo.ScriptLineNumber
    $name = $_.InvocationInfo.ScriptName
    Write-Error "caught exception: $e at script source $name($line)"
}

This will give you a complete trace-back and the source line number in your script where the error is happening. That should help you resolve issues on your own more quickly.