0
所以我有一個問題。我有一個ASP.NET Webforms應用程序。我正在使用SMO來做一些簡單的複製到另一個數據庫。整個例程通過我的本地IIS完美工作。我有一個嘗試抓住整個聲明。它返回錯誤:目錄'LocalApplicationData'不存在。「LocalApplicationData」目錄不存在。 - SQL SMO ASP.NET複製數據庫
任何人都可以幫助我嗎?我遍歷谷歌,但無法找到任何東西(我讀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'方法獲取該文件夾的路徑並查看會發生什麼。 – jmcilhinney
Ty的貢獻,但我解決了這個問題。另外,不確定你是否得到通知,但我回顧了你在回答問題時給出的答案,我回答了一些問題,我忽略了只是在沒有太多工作的情況下完成工作,你的方式就是做它:) – Billy