Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to connect to Azure SQL #1324

Open
7 tasks
davidkiss-nuvalence opened this issue Sep 27, 2021 · 10 comments
Open
7 tasks

Not able to connect to Azure SQL #1324

davidkiss-nuvalence opened this issue Sep 27, 2021 · 10 comments

Comments

@davidkiss-nuvalence
Copy link

davidkiss-nuvalence commented Sep 27, 2021

  • pgloader --version

    pgloader version "3.6.3~devel"
    compiled with SBCL 1.4.16.debian
    
  • did you test a fresh compile from the source tree?

    No

  • did you search for other similar issues?
    Yes

  • how can I reproduce the bug?

I tried migrating data from Azure SQL to Postgres using docker (see below command), but pgloader wasn't able to connect to Azure SQL due to use of unsupported USE command:

    sudo docker run --rm -v /tmp:/tmp -e TDSDUMP=/tmp/pgloader/freetds.log -e TDSVER=7.0 --name pgloader dimitri/pgloader:latest pgloader --debug --verbose --no-ssl-cert-verification mssql://<mssql username>:<mssql pwd>@<azure sql instance>.database.windows.net/<mssql db name> postgresql://<postgres username>:<postgres pwd>@<postgres hostname>/<postgres db name>

In the /tmp/pgloader/freetds.log file I found below error:

USE statement is not supported to switch between databases. Use a new connection to connect to a different database.

This is after pgloader sent below command to the mssql db:

SET ARITHABORT ON;SET CONCAT_NULL_YIELDS_NULL ON;SET ANSI_NULLS ON;SET ANSI_NULL_DFLT_ON ON;SET ANSI_PADDING ON;SET ANSI_WARNINGS ON;SET ANSI_NULL_DFLT_ON ON;SET CURSOR_CLOSE_ON_COMMIT ON;SET QUOTED_IDENTIFIER ON;USE [pgloader]

where pgloader is the mssql db name I used.

According to the Azure SQL docs, the USE command is not supported to switch to a different database:
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/use-transact-sql?view=sql-server-ver15

In Azure SQL Database, the database parameter can only refer to the current database. If a database other than the current 
database is provided, the USE statement does not switch between databases, and error code 40508 is returned.
  • pgloader output you obtain

image

  • data that is being loaded, if relevant
    N/A

  • How the data is different from what you expected, if relevant
    I expect pgloader to be able to connect to Azure SQL

@martinwiboe
Copy link

I'm also seeing this issue

@kvallab2
Copy link

We are running 3.6.6 and still getting the same issue while connecting to Azure SQL. Is there any fix to this issue?

@drog
Copy link

drog commented Aug 18, 2022

Same issue with 3.6.7 and a Azure SQL Server 2012

$ export TDSDUMP=~/tmp/freetds.log
$ pgloader --debug --dry-run mssql_instance.load

logs

dbutil.c:76:msgno 40508: "USE statement is not supported to switch between databases. Use a new connection to connect to a different database."
dblib.c:5094:default_err_handler 0x12f8043a0, 16, 20018, -1, 0x10130e6b8, 0x0dblib.c:5060:dbdead(0x12f8043a0) [alive]
token.c:2514:tds_process_info() returning TDS_SUCCESS
token.c:570:processing result tokens.  marker is  fd(DONE)
token.c:2100:tds_process_end: more_results = 0
		was_cancelled = 0
		error = 1
		done_count_valid = 0
token.c:2119:                rows_affected = 0
token.c:2122:tds_process_end() state set to TDS_IDLE
util.c:179:Changed query state from READING to IDLE
util.c:83:logic error: cannot change query state from IDLE to PENDING
util.c:179:Changed query state from IDLE to IDLE
dblib.c:4882:dbsqlok() end status is 0 (FAIL)

@dimitri
Copy link
Owner

dimitri commented Aug 19, 2022

I believe the problem lies in the MS SQL driver that pgloader depends on. Specifically see:

https://github.com/archimag/cl-mssql/blob/045602a19a32254108f2b75871049293f49731eb/src/connection.lisp#L73

Could you please open an issue there and follow-up when we have a fix for it?

@bestekov
Copy link

bestekov commented Nov 10, 2022

Created the above issue. Though is there anything that can be done in the meantime to workaround this issue?

Although I also do not see any /tmp/pgloader/freetds.log file like the original report mentioned... so not sure if this is truly the cause of the issue?

I am running pgloader in a docker container.

I am just getting:

2022-11-10T05:05:26.180000Z ERROR mssql: Failed to connect to mssql at "xxx.database.windows.net" (port 1433) as user "xxx": %dbsqlexec fail

@bestekov
Copy link

Hmm... the maintainer of that dependency says they are not maintaining it anymore.... any other option for fixing Azure connectivity?

@michivi
Copy link

michivi commented Nov 18, 2023

Stumbled upon the same issue ourselves. archimag/cl-mssql#10 fixes it in our case.

@jahangiranwari
Copy link

Here's an updated pgloader Docker image with the fix.

@geohernandez
Copy link

geohernandez commented Apr 15, 2024

Hi jahangiranwari

I pulled this Docker image, however, when I tried to use pgloader, I got this error message:
pgloader --version
qemu-aarch64: Could not open '/lib/ld-linux-aarch64.so.1': No such file or directory

Any idea of how to solve, I am using Docker (Docker version 25.0.3, build 4debf41) on Win11.

Additionally, I created a Debian VM and got issues too.

@geohernandez
Copy link

Hi jahangiranwari

My colleague Esteban found the issue, apparently, you built the image on ARM (maybe Mac) and it was not compatible with x86, so basically it was recompiled using the pgloader exe from Dimitri and your code. In this link, we have the functional image for x86, all the credit to you.

docker pull esbalo/pgloader
docker run --rm -it esbalo/pgloader:1.0.0 pgloader --version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants