SQL Connection Using Active Directory / Microsoft Entra
We use Active Directory aka Microsoft Entra to authenticate with all of our SQL servers. I'm not able to find a way to connect using NetPad 0.8.0. Azure Data Studio has the best support/implementation for this. Do you have plans to add this to NetPad? I'd love to use it.
I think it would be a great addition. Its not on README roadmap but it is planned.
not a solution, just a bit more details:
it is possible to add a "Custom" part to the connection string, for example:
Persist Security Info=False;User [email protected];Authentication="Active Directory Interactive";Encrypt=True;
as a result you get the connection string like this:
Data Source=xxxxx.database.windows.net,1433;Initial Catalog=xxxxxxxx;Persist Security Info=False;User [email protected];Authentication="Active Directory Interactive";Encrypt=True;
this creates a connection. However the scaffolding shows error:
Scaffolding process failed with exit code: 1.
Output: Specify --help for a list of available options and commands.
Unrecognized command or argument 'Interactive;Encrypt=True;'
Error:
@Tridy can you try removing the double quotes from:
Authentication="Active Directory Interactive"
So it's just
Authentication=Active Directory Interactive
That indeed helped to start scaffolding
However in the process it still got an error:
Could not get database structure during scaffolding. Check the logs at: /home/xxx/.local/share/NetPad/Logs
From the log I can see that it is indeed reading database structure and there is output for several tables in the log.
The error that I can see the most in the log is this:
Unrecognized command or argument 'Interactive;Encrypt=True;'
My guess is that it does not like the Interactive part from the "Active Directory Interactive"
and here are some other lines that might have some information
System.Text.Json.JsonException: '/' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
---> System.Text.Json.JsonReaderException: '/' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
...
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at NetPad.Common.JsonSerializer.Deserialize[T](String json) in /home/tips/Source/TIPS/NetPad/src/Core/NetPad.Runtime/Common/JsonSerializer.cs:line 36
at NetPad.Apps.Data.EntityFrameworkCore.Scaffolding.EntityFrameworkDatabaseScaffolder.GetDatabaseStructureAsync(DotNetCSharpProject project, String dbContextClassName) in /home/tips/Source/TIPS/NetPad/src/Apps/NetPad.Apps.Common/Data/EntityFrameworkCore/Scaffolding/EntityFrameworkDatabaseScaffolder.cs:line 130
System.Exception: Could not get database structure during scaffolding. Check the logs at: /home/xxx/.local/share/NetPad/Logs
at NetPad.Apps.Data.EntityFrameworkCore.EntityFrameworkDatabaseConnectionMetadataProvider.GetDatabaseStructureAsync(DatabaseConnection databaseConnection) in /home/tips/Source/TIPS/NetPad/src/Apps/NetPad.Apps.Common/Data/EntityFrameworkCore/EntityFrameworkDatabaseConnectionMetadataProvider.cs:line 41
at NetPad.Apps.CQs.GetDatabaseConnectionStructureQuery.Handler.Handle(GetDatabaseConnectionStructureQuery request, CancellationToken cancellationToken) in /home/tips/Source/TIPS/NetPad/src/Apps/NetPad.Apps.Common/CQs/GetDatabaseConnectionStructureQuery.cs:line 17
at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
at NetPad.Services.MediatorRequestPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next) in /home/tips/Source/TIPS/NetPad/src/Apps/NetPad.Apps.App/Services/MediatorRequestPipeline.cs:line 18
at NetPad.Plugins.OmniSharp.OmniSharpMediatorPipeline`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next) in /home/tips/Source/TIPS/NetPad/src/Plugins/NetPad.Plugins.OmniSharp/OmniSharpMediatorPipeline.cs:line 15
at NetPad.Controllers.DataConnectionsController.GetDatabaseStructure(Guid id) in /home/tips/Source/TIPS/NetPad/src/Apps/NetPad.Apps.App/Controllers/DataConnectionsController.cs:line 103
at lambda_method154(Closure , Object )
...
at NetPad.Middlewares.ExceptionHandlerMiddleware.InvokeAsync(HttpContext httpContext) in /home/tips/Source/TIPS/NetPad/src/Apps/NetPad.Apps.App/Middlewares/ExceptionHandlerMiddleware.cs:line 32
2024-11-14T22:18:09.6337918+01:00 [ERR] (PID: 137620|NetPad.Apps.Data.EntityFrameworkCore.Scaffolding.EntityFrameworkDatabaseScaffolder) Ran database structure generation successfully but failed to deserialize output. JSON: /tmp/NetPad/TypedDataContexts/40f43120-5c33-4f3c-8178-b37039442cb2/DataConnection_40f43120-5c33-4f3c-8178-b37039442cb2.csproj
Same issue here, even without using AAD, using Username/Password authentication:
NetPad.Apps.Data.EntityFrameworkCore.Scaffolding.EntityFrameworkDatabaseScaffolder) Ran database structure generation successfully but failed to deserialize output. JSON: /
System.Text.Json.JsonException: '/' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
---> System.Text.Json.JsonReaderException: '/' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)
at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)
at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
at System.Text.Json.Utf8JsonReader.Read()
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at NetPad.Common.JsonSerializer.Deserialize[T](String json) in /Users/user248920/Downloads/source/NetPad/src/Core/NetPad.Runtime/Common/JsonSerializer.cs:line 36
at NetPad.Apps.Data.EntityFrameworkCore.Scaffolding.EntityFrameworkDatabaseScaffolder.GetDatabaseStructureAsync(DotNetCSharpProject project, String dbContextClassName) in /Users/user248920/Downloads/source/NetPad/src/Apps/NetPad.Apps.Common/Data/EntityFrameworkCore/Scaffolding/EntityFrameworkDatabaseScaffolder.cs:line 130