【发布时间】:2016-04-26 22:45:42
【问题描述】:
所以我有一个问题。我有一个 ASP.NET Webforms 应用程序。我正在使用 SMO 进行一些简单的复制到另一个数据库。整个例程通过我的本地 IIS 完美运行。我对整个声明有一个 Try Catch。它返回错误:目录“LocalApplicationData”不存在。
谁能帮我解决这个问题?我遍历了谷歌,但找不到任何东西(我读过https://social.technet.microsoft.com/Forums/systemcenter/en-US/34fd1bce-e9a3-40bc-8d18-f80fe4ec7aaf/localapplicationdata-does-not-exist?forum=sqlsmoanddmo,但需要更好的解释)。
我的代码:
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports Microsoft.SqlServer.Management.Smo
Public Class betatolive
Inherits System.Web.UI.Page
Public Shadows User As clsUser = New clsUser(Me.Page)
Private Sub betatolive_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If User.Data.fUserLevel < 98 Then Response.Redirect("~/Admin/")
End Sub
Private Sub lnkTransferData_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim feedback As String = "Transfer successful."
Try
Dim dbSrcServer = New Server("123.192.4.567,1337")
With dbSrcServer.ConnectionContext
.LoginSecure = False
.Login = "username"
.Password = "password"
.Connect()
End With
Dim dbSource As Database = dbSrcServer.Databases("dTransferSource")
Dim dbDest As Database = dbSrcServer.Databases("dTransferDest")
Dim dbTransfer As New Transfer(dbSource)
For Each t As Table In dbSource.Tables
If Not t.Name.Contains("OBSOLETE") And Not t.Name = "name" Then
dbTransfer.ObjectList.Add(t)
End If
Next
Dim dropDestTables As New List(Of Table)
For Each t As Table In dbDest.Tables
If Not t.Name = "name1" And Not t.Name = "name2" And Not t.Name = "name3" Then
dropDestTables.Add(t)
End If
Next
For Each t As Table In dropDestTables
dbDest.Tables(t.Name).Drop()
Next
Dim transferOpts As New ScriptingOption
With transferOpts
.ClusteredIndexes = True
.Default = True
.FullTextIndexes = True
.Indexes = True
.NonClusteredIndexes = True
End With
With dbTransfer
.CopySchema = True
.CopyData = True
.CopyAllObjects = False
.CopyAllTables = False
.Options = transferOpts
.DestinationServer = dbSrcServer.Name
.DestinationDatabase = dbVaDest.Name
.DestinationLoginSecure = False
.DestinationLogin = "username"
.DestinationPassword = "password"
End With
dbTransfer.TransferData()
Catch ex As Exception
feedback = String.Format("Please do not attempt the transfer again until further notice. <br /> Transfer Error: " & ex.InnerException.Message())
End Try
lnkTransferData.Text = feedback
lnkTransferData.Enabled = False
End Sub
End Class
【问题讨论】:
-
我假设
LocalApplicationData指的是Environment.SpecialFolder.LocalApplicationData成员。尝试使用Environment.GetFolderPath方法获取该文件夹的路径,看看会发生什么。 -
Ty 的贡献,但我解决了这个问题。另外,不确定您是否收到通知,但是我回顾了您在不久前提出的一个问题上给出的答案它:)
标签: sql sql-server vb.net iis smo