2016-04-26 7 views
0

私は問題があります。私はASP.NET Webformsアプリケーションを持っています。私はSMOを使って別のデータベースに単純なコピーをしています。ルーチン全体は、ローカルのIISを通じて完全に動作します。私は全体の声明のまわりでTry Catchを持っています。それは私にエラーを返します:ディレクトリ 'LocalApplicationData'が存在しません。ディレクトリ 'LocalApplicationData'が存在しません。 - SQL SMOのASP.NETデータベースをコピー

誰もがこれを手伝ってくれますか?私はGoogleを横断しましたが、何も見つかりませんでした(私は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 
+0

私は 'LocalApplicationData'が' Environment.SpecialFolder.LocalApplicationData'メンバを参照していると仮定します。 'Environment.GetFolderPath'メソッドを使って、そのフォルダのパスを取得し、何が起こるかを見てください。貢献のために – jmcilhinney

+0

Tyが、問題を修正しました。また、あなたが通知を受けているかどうかは分かりませんが、私はあなたが質問したあなたの答えを振り返りました。それ :) – Billy

答えて

0

を修正しました。

With dbTransfer 
    .CopySchema = True 
    .CopyData = True 
    .CopyAllObjects = False 
    .CopyAllTables = False 
    .Options = transferOpts 
    .TemporaryPackageDirectory = Server.MapPath("~/dbtemp") ' This is the fix, had to create a temp folder and set that property to the path 
    .DestinationServer = dbSrcServer.Name 
    .DestinationDatabase = dbVaDest.Name 
    .DestinationLoginSecure = False 
    .DestinationLogin = "username" 
    .DestinationPassword = "password" 
End With 

@jmcilhinney - ちょうどFYI、私はあなたが言ったことをやった、それは多分それは設定する必要がアイデアを私に指摘し、空白文字列を返しますので、私は、参照をチェックし、そのプロパティを見つけました上記。

あなたのご意見ありがとうございます、私はあなたが提案したことを考えていなかったし、私は問題を解決するためにそれを導く。