相关疑难解决方法(0)

在ASP.Core中找不到WindowsImpersonationContext和Impersonate()

我在.NET Framework 4.0程序集中具有以下内容:

var newId= new WindowsIdentity(duplicateTokenHandle);
WindowsImpersonationContext newId = ImpersonatedIdentity.Impersonate();
Run Code Online (Sandbox Code Playgroud)

我将它移植到ASP.Core,但WindowsImpersonationContextWindowsIdentity.Impersonate()没有找到。

我尝试添加以下内容:

  • System.Security.Claims 4.3.0
  • System.Security.Principal 4.3.0
  • System.Security.Principal.Windows 4.4.0

如何在ASP.Core中执行模拟?

更新资料

看起来.NET Core或.NET Standard不支持它-是否有解决方法,或者我必须辞职才能针对框架吗?

.net asp.net impersonation .net-core asp.net-core

9
推荐指数
2
解决办法
5264
查看次数

Invoke-SQLCmd具有不同的凭据

背景:我在本地运行一个必须以SYSTEM身份运行的脚本,让我们不了解为什么会这样.:)该脚本尝试使用简单查询检查我的MSSQL集群的运行状况.然而,我遇到的问题是本地SYSTEM帐户无权访问远程数据库.在这一点上,我已经尝试了很多东西,我将在稍后介绍,但我老实说,任何有意义的解决方案.如果这意味着在数据库中创建一个本地帐户,可以回答我的简单查询.

到目前为止我有:

$Server = 'myserver.domain.tld'
$Database = 'myDatabase'
$Query = 'SELECT DB_NAME() AS DataBaseName'
$Username = 'myDomain\myUsername'
$Password = 'myPasswordWithPlainText'
Invoke-SQLCmd -ServerInstance $Server -Database $Database -ConnectionTimeout 300 -QueryTimeout 600 -Query $Query -Username $Username -Password $Password
Run Code Online (Sandbox Code Playgroud)

结果: Invoke-Sqlcmd : Login failed for user 'myDomain\myUsername'

也许Invoke-SQL没有采用我认为的Windows身份验证,但它不使用-Credential.所以我尝试使用Invoke-Command作为包装器.

$Server = 'myserver.domain.tld'
$Database = 'myDatabase'
$Query = 'SELECT DB_NAME() AS DataBaseName'
$Username = 'myDomain\myUsername'
$Password = 'myPasswordWithPlainText'
$secpasswd = ConvertTo-SecureString $Password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)
Invoke-Command -script {Invoke-SQLCmd -ServerInstance $Server -Database …
Run Code Online (Sandbox Code Playgroud)

sql-server powershell

6
推荐指数
2
解决办法
3万
查看次数

使用Windows身份验证从非域计算机访问SQL Server 2005

我有一个Windows域,其中一台机器运行SQL Server 2005,并配置为仅支持Windows身份验证.我想在同一网络上的计算机上运行C#客户端应用程序,但不在域上,并访问SQL Server 2005实例上的数据库.

我认为做这样的事情会很简单:

string connectionString = "Data Source=server;Initial Catalog=database;User Id=domain\user;Password=password";
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
Run Code Online (Sandbox Code Playgroud)

但是,这失败了:客户端错误是:

System.Data.SqlClient.SqlException:用户'domain\user'登录失败,服务器端错误为:错误18456,严重级别14,状态5

我尝试了各种各样的事情,包括将集成安全性设置为true和false,以及\而不是用户ID中的\,但没有成功.

一般来说,我知道可以从非域计算机连接到SQL Server 2005实例(例如,我正在使用基于Linux的应用程序,很高兴这样做),但我似乎无法找出如何从Windows机器上做到这一点.

c# windows sql-server security dns

5
推荐指数
2
解决办法
2397
查看次数

访问不同Active Directory服务器中的数据库

我目前登录到Active Directory域A上的用户计算机,我需要通过VB6访问位于域B中的MSSQL 2000中的数据库.用户在两个Active Directory服务器中都有帐户.Active Directory域不相关或链接.

目前我正在使用以下MSSQL连接字符串:

gcnnBD.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & gsDataBase & ";Data Source=" & gsServidor & ";Connect Timeout=" & gsTimeOutconnection string.
Run Code Online (Sandbox Code Playgroud)

如果我登录到域A,是否可以通过连接字符串连接到域B?

连接字符串是什么样的?

欢迎任何建议.

sql-server vb6 active-directory

5
推荐指数
1
解决办法
546
查看次数

无法使用域凭据从PowerShell连接到SQL Server

我有一个无法使用域凭据连接到SQL Server的问题。使用SA凭据可以正常工作,查询将按预期运行。但是,当我使用域凭据时,会出现错误。

这是脚本:

$SQLServer = 'server.domain.com'
$SQLDBName = 'DBname'
$username  = "DOMAIN\user"
$password  = "password"

$SqlConnection = New-Object System.Data.SqlClient.SqlConnection

#--> With SA, it works, with DOMAIN creds, it does not

#$SqlConnection.ConnectionString = "Server=$SQLServer; Database=$SQLDBName; User ID=sa; Password=SApassword;"
$SqlConnection.ConnectionString = "Server=$SQLServer; Database=$SQLDBName; User ID=$username; Password=$password;"

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = 'select count (*) from my.table'
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$SqlConnection.Close()
$DataSet.Tables[0]
Run Code Online (Sandbox Code Playgroud)

这是我运行脚本时遇到的错误:

使用“ 1”参数调用“填充”的异常:“建立与SQL Server的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问该服务器。请验证实例名称是否正确并且该SQL Server配置为允许远程连接(提供程序:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

在C:\ scripts …

sql-server powershell windows-security

4
推荐指数
1
解决办法
4万
查看次数