我正在尝试使用Powershell部署数据库dacpac并在下面接收到错误。有人知道怎么修这个东西吗?我在想这是由于我拥有SQL Server2016。试图了解错误消息的含义。 这是代码:主要错误似乎无法连接到本地主机???这个基本的用户访问权限。我尝试右键单击并在Powershell上以管理员身份运行,仍然无法正常工作。
add-type -path "C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin\Microsoft.SqlServer.Dac.dll"
$dacService = new-object Microsoft.SqlServer.Dac.DacServices "server=localhost"
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load("C:\Test\ScaffoldTest.dacpac")
try
{
$dacService.deploy($dp, "ScaffoldTest", "True")
}
catch
{
Write-Host "LoadException";
$Error | format-list -force
Write-Host $Error[0].Exception.ParentContainsErrorRecordException;
}
错误:
Exception calling "Deploy" with "3" argument(s): "Could not deploy package."
At line:32 char:1
+ $dacService.deploy($dp, "ScaffoldTest", "True")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DacServicesException
Exception : System.Management.Automation.MethodInvocationException: Exception calling "Deploy" with "3" argument(s): "Could not deploy package." --->
Microsoft.SqlServer.Dac.DacServicesException: Could not deploy package. ---> Microsoft.Data.Tools.Schema.Sql.Deployment.DeploymentFailedException: Unable to connect
to target server 'localhost'. Please verify the connection information such as the server name, login credentials, and firewall rules for the target server. --->
System.Data.SqlClient.SqlException: Login failed for user ''.
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential,
Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData
reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo,
DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions
userOptions)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions,
DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory,
TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.Data.Tools.Schema.Common.SqlClient.ReliableSqlConnection.<OpenConnection>b__0()
at Microsoft.Data.Tools.Schema.Common.SqlClient.RetryPolicy.<>c__DisplayClass4.<ExecuteAction>b__3(RetryState retryState)
at Microsoft.Data.Tools.Schema.Common.SqlClient.RetryPolicy.ExecuteAction[R](Func`2 func, Nullable`1 token)
at Microsoft.Data.Tools.Schema.Common.SqlClient.RetryPolicy.ExecuteAction(Action`1 action, Nullable`1 token)
at Microsoft.Data.Tools.Schema.Common.SqlClient.RetryPolicy.ExecuteAction(Action action, Nullable`1 token)
at Microsoft.Data.Tools.Schema.Common.SqlClient.ReliableSqlConnection.OpenConnection()
at Microsoft.Data.Tools.Schema.Common.SqlClient.ReliableConnectionHelper.OpenConnection(SqlConnectionFactory connectionFactory, Boolean useRetry)
at Microsoft.Data.Tools.Schema.Common.SqlClient.ReliableConnectionHelper.OpenConnection(SqlConnectionFactory connectionFactory, Action`1 usingConnection,
Predicate`1 catchException, Boolean useRetry)
at Microsoft.Data.Tools.Schema.Common.SqlClient.ReliableConnectionHelper.GetServerAndDatabaseVersion(SqlConnectionFactory connectionFactory,
ServerAndDatabaseInfo& info)
at Microsoft.Data.Tools.Schema.Sql.SqlDatabaseSchemaProviderFamily.DetermineSqlPlatform(SqlConnectionFactory connectionFactory, CompatibilityLevelVerification
verificationMode, String& errorMessage)
at Microsoft.Data.Tools.Schema.Sql.SqlDatabaseSchemaProviderFamily.DetermineDatabaseSchemaProvider(SqlConnectionFactory connectionFactory, String& errorMessage)
at Microsoft.Data.Tools.Schema.Sql.SqlDatabaseSchemaProviderFamily.DetermineDatabaseSchemaProvider(SqlConnectionFactory connectionFactory)
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentEndpointServer.GetProviderType(DatabaseSchemaProviderFamily connectionSniffer, SqlConnectionFactory
connectionFactory, Type& providerType, Boolean& validDataSource, SqlException& exception)
--- End of inner exception stack trace ---
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentEndpointServer.OnInit(ErrorManager errors, String targetDBName)
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment..ctor(SqlDeploymentConstructor constructor)
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentConstructor.ConstructServiceImplementation()
at Microsoft.SqlServer.Dac.DacServices.CreatePackageToDatabaseDeployment(SqlConnectionFactory connectionFactory, IPackageSource packageSource, String
targetDatabaseName, DacDeployOptions options, ErrorManager errorManager)
at Microsoft.SqlServer.Dac.DeployOperation.<>c__DisplayClass3.<>c__DisplayClass5.<CreatePlanInitializationOperation>b__1()
at Microsoft.Data.Tools.Schema.Sql.Dac.OperationLogger.Capture(Action action)
at Microsoft.SqlServer.Dac.DeployOperation.<>c__DisplayClass3.<CreatePlanInitializationOperation>b__0(Object operation, CancellationToken token)
at Microsoft.SqlServer.Dac.Operation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.ReportMessageOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.OperationExtension.CompositeOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.OperationExtension.CompositeOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.DeployOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Dac.DeployOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.OperationExtension.Execute(IOperation operation, DacLoggingContext loggingContext, CancellationToken cancellationToken)
at Microsoft.SqlServer.Dac.DacServices.InternalDeploy(IPackageSource packageSource, Boolean isDacpac, String targetDatabaseName, DacDeployOptions options,
CancellationToken cancellationToken, DacLoggingContext loggingContext, Action`3 reportPlanOperation, Boolean executePlan)
at Microsoft.SqlServer.Dac.DacServices.Deploy(DacPackage package, String targetDatabaseName, Boolean upgradeExisting, DacDeployOptions options, Nullable`1
cancellationToken)
at CallSite.Target(Closure , CallSite , Object , Object , String , String )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
答案 0 :(得分:0)
如果您的SQL Server使用Windows身份验证,则需要在您的连接字符串中指出这一点:
$dacService = new-object Microsoft.SqlServer.Dac.DacServices "server=localhost;Integrated Security=True;"