Git Product home page Git Product logo

Comments (9)

kburtram avatar kburtram commented on September 9, 2024

@potatoqualitee I'm not sure this question is related to this code repo, at least I can't immediately see the direct relationship.

@Matteo-T @shueybubbles do you have more context on this question?

from sqltoolsservice.

Matteo-T avatar Matteo-T commented on September 9, 2024

Yeah - unrelated to this repo.
Could @potatoqualitee (aka Chrissy) elaborate on the "sometimes"? And, more importantly, on some SMO code that is being executed behind the scenes?
Probably easier to ping me and @shueybubbles directly (it seems a SMO thingie).

from sqltoolsservice.

potatoqualitee avatar potatoqualitee commented on September 9, 2024

@kburtram - my apologies, I saw some SMO related questions and thought this would be the place.

@Matteo-T Yes, I can elaborate on sometimes.

This will succeed 100% of the time:

$azSqlCn = Connect-DbaInstance @params
$azSqlCn.Databases.Name

This will fail 100% of the time with the blank login failure:

Get-DbatoolsLog | Select -First 1 | Write-DbaDataTable -SqlInstance $azSqlCn -Database abc -Table ThisisErrorLog -AutoCreateTable

In the future, shall I just ping you guys from the dbatools repo?
Thanks,
Chrissy

from sqltoolsservice.

Matteo-T avatar Matteo-T commented on September 9, 2024

Not sure how effective that is going to be: I get way too much traffic from GitHub and it is easy for me to miss communications. The important thing, IMHO, is that if this is a SMO issue (under the hood), you should give me/David/etc something that is SMO code ore than asking us to dig into the implementation of the DbaTools module (it does not have to be C# code, PowerShell is fine. But make it look like a few lines of .NET/SMO code).

from sqltoolsservice.

potatoqualitee avatar potatoqualitee commented on September 9, 2024

Thanks

$accesstoken = "bigolaccesstoken"
$databasename = "abc"
$connstring = 'Data Source=TCP:psdbatools.database.windows.net,1433;Initial Catalog=abc;Persist Security Info=True;MultipleActiveResultSets=False;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False;Application Name="dbatools PowerShell module - dbatools.io"'

$sqlconn = New-Object System.Data.SqlClient.SqlConnection $connstring
$sqlconn.AccessToken = $AccessToken
$serverconn = New-Object Microsoft.SqlServer.Management.Common.ServerConnection $sqlconn
$null = $serverconn.Connect()
$server = New-Object Microsoft.SqlServer.Management.Smo.Server $serverconn

# works
$server.Databases.Name

# also works
$db = $server.Databases[$databaseName]
$db.Name

# breaks
$db.Tables.Name

# also breaks
$db.Tables.Refresh()

breaks with:

The following exception occurred while trying to enumerate the collection: "Failed to connect to server TCP:psdbatools.database.windows.net,1433.".

and more detailed

PSMessageDetails      :
Exception             : System.Management.Automation.ExtendedTypeSystemException: The following exception occurred while trying to enumerate the collection: "Failed to
                        connect to server TCP:psdbatools.database.windows.net,1433.". ---> Microsoft.SqlServer.Management.Common.ConnectionFailureException: Failed to
                        connect to server TCP:psdbatools.database.windows.net,1433. ---> System.Data.SqlClient.SqlException: Login failed for user ''.

from sqltoolsservice.

shueybubbles avatar shueybubbles commented on September 9, 2024

If you can use .Net 4.7.2, I recommend using 'Authentication=Active Directory Interactive' in the connection string, and install a SqlAuthenticationProvider implementation to provide the token. Look up SqlAuthenticationProvider.SetProvider.

Otherwise, the only way the ServerConnection object can assign an access token to SqlConnection objects it creates is if you pass in an IRenewableToken implementation to its constructor.
SMO sometimes creates new connections behind your back, which leads to these errors if you don't use either Interactive auth or IRenewableToken.

from sqltoolsservice.

potatoqualitee avatar potatoqualitee commented on September 9, 2024

Thanks shuey! I'll take a look.

from sqltoolsservice.

potatoqualitee avatar potatoqualitee commented on September 9, 2024

can confirm this appraoch works! (from azurevm, still trying to get it using a SqlAuthenticationProvider implementation
image

from sqltoolsservice.

potatoqualitee avatar potatoqualitee commented on September 9, 2024

Got it using SqlAuthenticationProvider as well 💯 incredibly fast!

image

from sqltoolsservice.

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.