GithubHelp home page GithubHelp logo

Comments (4)

JacktnielFD20 avatar JacktnielFD20 commented on September 7, 2024

Check network connectivity: Make sure that Azure Cloud Shell has access to the Internet and that there are no network restrictions that might be blocking the connection to your Azure SQL database.Update the SqlServer module: Although you mentioned that you have already updated the SqlServer module to the latest version, there might be some incompatibility or specific issue that has not been addressed yet. Try using an older version of the SqlServer module to see if that fixes the problem.Try different authentication methods: If the connection works with "Active Directory Password" but not with "Active Directory Default", there might be a problem with the way authentication is done. Try using different supported authentication methods to see if that resolves the issue.Check your account settings: Make sure your Azure account has the proper permissions to access the SQL database and perform theauthentication using the selected method.Contact Azure support: If you've tried the above solutions and still can't resolve the issue, I would recommend contacting Azure support. They will have access to the most up-to-date information and tools to help you resolve your specific Azure Cloud Shell issue.

from cloudshell.

sidesw1pe avatar sidesw1pe commented on September 7, 2024

Thanks for the suggestions. There seems to be a difference between the terminal-based Cloud Shell vs the Cloud Shell in the Azure portal, based on the edit I added to the Additional context in my original post. I don't see that is my specific issue.

from cloudshell.

theJasonHelmick avatar theJasonHelmick commented on September 7, 2024

Hi @sidesw1pe - Thank you for reporting this issue. Can you confirm, this works when you are logged into the portal, but does not work in Terminal? Can you also confirm that the account you are using with terminal is the same account you use for portal? Could you supply the output for both portal and terminal of the following command: az account show

from cloudshell.

sidesw1pe avatar sidesw1pe commented on September 7, 2024

Hi @theJasonHelmick ,

Azure Cloud Shell (Terminal)

I am logged on to my desktop (laptop) with [email protected] (Azure AD account). I start a new Azure Cloud Shell session via Windows Terminal. It prompts me to visit https://microsoft.com/devicelogin and enter the provided code. I do this, select my account, and close the tab. Back at the Cloud Shell, and it prompts me to select my Tenant, which I do (in my case there are 2 tenants to choose from, so I naturally select the one associated with the Azure SQL Database I am interested in). After the authentication process completes I am left at the command prompt. I run the command (Get-AzAccessToken).UserId and it returns MSI@***** (where ***** is a 5 digit number).

Azure Cloud Shell (Azure Portal)

I log in to the portal using my Azure AD account [email protected]. This is the same user as I used above. I open the Azure Cloud Shell by clicking on "Cloud Shell" at the top. After it authenticates I am left at the command prompt. I run the command (Get-AzAccessToken).UserId and it returns MSI@***** (where ***** is a 5 digit number). This is the same number as above.

In both shells above, I run the following commands:

Import-Module SqlServer
$newcon = New-Object Microsoft.SqlServer.Management.Common.ServerConnection
$newcon.ConnectionString = "Data Source=mysqlserver.database.windows.net;Initial Catalog=mydb;Encrypt=False;Trust Server Certificate=False;Authentication=ActiveDirectoryDefault"
$newcon.Connect()

From the Terminal Cloud Shell, after a brief period, I get this error:

MethodInvocationException: Exception calling "Connect" with "0" argument(s): "Failed to connect to server mysqlserver.database.windows.net."

After getting the error, I ran Get-Error and saved the output, in case it is of use.
connect_error.txt

From the Portal Cloud Shell it connects right away (no error is given). I can then, for example, use the connection to create a new server object and get details back from the server.

While documenting this for my response, I noticed that after I get a successful connection from the Portal Cloud Shell, the connection then succeeds from the Terminal Cloud Shell. It's not just a timing issue. I had tried repeatedly from my Terminal, even with a 10 minute wait in between, and consistently got the error message mentioned. I then tried the Portal Cloud Shell, and after connecting successfully, I immediately retried my Terminal Cloud Shell, and it connected right away. I exited from both Cloud Shells, and reauthenticated with my Terminal Cloud Shell, and I could still successfully connect to my SQL db. However after waiting for some time, say 30 minutes or more, the original problem would return.

Here is the output from az account show. It is identical in both Cloud Shells, Terminal and Portal.

{
  "environmentName": "AzureCloud",
  "homeTenantId": "94fd9d0a-7823-48d8-be50-0c6559650cc9",
  "id": "16afc5ef-0971-4cf2-bcdc-25a5e8f4e189",
  "isDefault": true,
  "managedByTenants": [],
  "name": "mysub",
  "state": "Enabled",
  "tenantId": "94fd9d0a-7823-48d8-be50-0c6559650cc9",
  "user": {
    "cloudShellID": true,
    "name": "[email protected]",
    "type": "user"
  }
}

from cloudshell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.