Smo sqlbackup run netframework2 but don't run net framework 4

Unanswered Smo sqlbackup run netframework2 but don't run net framework 4

  • 27 ธันวาคม 2554 21:22
     
     

    Hello,

     this code also works fine in NET2 and net3  , but does not work in NET4

    windows7 x86

    sqlserver2005 express sp4

     

    referances: Microsoft.SqlServer.Smo,Microsoft.SqlServer.SmoEnum,Microsoft.SqlServer.ConnectionInfo

     

    Dim WithEvents backup1 As Backup
      

    Private Sub MakeBackup()
            Dim SaveFileDialog1 As New SaveFileDialog
            With SaveFileDialog1
                .Filter = "Backup Files|*.bak"
                .Title = "Backup File."
                .FileName = "Yedek_Aktivasyon_" & Today.Day & "_" & Today.Month & "_" & Today.Year
                If .ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                    If .FileName <> "" Then
                        Try
                          
                            Dim srv As Server = New Server("(local)")
                            backup1 = New Backup()
                            backup1.Devices.AddDevice(.FileName, DeviceType.File)
                            backup1.Database = "mydatabasename"
                            backup1.Action = BackupActionType.Database
                            backup1.Incremental = False
                            backup1.Initialize = True
                            backup1.PercentCompleteNotification = 1
                            backup1.SqlBackup(srv)
                            MessageBox.Show("successful")
                         

                        Catch ex As Exception
                           MessageBox.Show("unsuccessful")
                         
                        End Try

                    End If
                End If



            End With




        End Sub

ตอบทั้งหมด

  • 29 ธันวาคม 2554 3:29
     
      มีโค้ด

    Hi SOFTTURK YAZILIM,

    Could you please explian "does not work in NET4" a bit? Do you get any error messsage?

    Your code works fine on my machine (Windows 7 64-bit, SQL Server 2008 R2 Developer 64-bit and Visual Studio 2010)

    Dim SaveFileDialog1 As New SaveFileDialog
    With SaveFileDialog1
    .Filter = "Backup Files|*.bak"
    .Title = "Backup File."
    .FileName = "Yedek_Aktivasyon_" & Today.Day & "_" & Today.Month & "_" & Today.Year
    If .ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        If .FileName <> "" Then
            Try
    
                Dim srv As Server = New Server("(local)")
                Dim backup1 As New Backup
                backup1.Devices.AddDevice(.FileName, DeviceType.File)
                backup1.Database = "northwind"
                backup1.Action = BackupActionType.Database
                backup1.Incremental = False
                backup1.Initialize = True
                backup1.PercentCompleteNotification = 1
                backup1.SqlBackup(srv)
                MessageBox.Show("successful")
    
    
            Catch ex As Exception
                MessageBox.Show("unsuccessful")
            End Try
    
        End If
    End If
    

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Get or Request Code Sample from Microsoft
    If you have any feedback, please tell us.
  • 30 ธันวาคม 2554 10:14
    ผู้ดูแล
     
     

    Hello Jian kiang,

    I may go wrong , but i think that there is a problem of version of SMO between .Net 4.0 and SQL Server 2005. As usually, you are my main provider of good ideas/solutions about Smo, i prefer to ask you this question even if i am going wrong ( i think that there was a thread 2 years ago about a similar problem ).

    Have a nice day and happy new year


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
  • 2 มกราคม 2555 16:17
    ผู้ดูแล
     
     

    Hello,

    It is better to install the .Net Framework 2.0 SDK but, if my remembrance is good for the install ofSQL Server 2008 R2 Express and VC# 2010 on a Windows 7, it is the SDK of .Net Framework 3.5 which must be installed as it is including the .Net Framework 2.0

    Some useful links :

    http://msdn.microsoft.com/en-US/library/ms162161(v=SQL.90).aspx

    http://msdn.microsoft.com/en-US/library/ms162167(v=SQL.90).aspx

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
  • 2 มกราคม 2555 16:22
    ผู้ดูแล
     
     

    Hello,

    Last link about this problem :

    http://social.msdn.microsoft.com/Forums/en-US/sqlsmoanddmo/thread/533f7044-1109-4b7a-a697-2621f23017d6

    The post of Jian Kang could be useful ( if i have not been betrayed by my poor english);

    Anyway, have all a happy new year ( for people concerned by this old habit for europeans/americans )

    Have a nice day

     


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
  • 14 มกราคม 2555 13:58
     
     

    Hello,

     this code also works fine in NET2 and net3  , but does not work in NET4

    windows7 x86

    sqlserver2005 express sp4

     

    referances: Microsoft.SqlServer.Smo,Microsoft.SqlServer.SmoEnum,Microsoft.SqlServer.ConnectionInfo

     

    Dim WithEvents backup1 As Backup
      

    Private Sub MakeBackup()
            Dim SaveFileDialog1 As New SaveFileDialog
            With SaveFileDialog1
                .Filter = "Backup Files|*.bak"
                .Title = "Backup File."
                .FileName = "Yedek_Aktivasyon_" & Today.Day & "_" & Today.Month & "_" & Today.Year
                If .ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                    If .FileName <> "" Then
                        Try
                          
                            Dim srv As Server = New Server("(local)")
                            backup1 = New Backup()
                            backup1.Devices.AddDevice(.FileName, DeviceType.File)
                            backup1.Database = "mydatabasename"
                            backup1.Action = BackupActionType.Database
                            backup1.Incremental = False
                            backup1.Initialize = True
                            backup1.PercentCompleteNotification = 1
                            backup1.SqlBackup(srv)
                            MessageBox.Show("successful")
                         

                        Catch ex As Exception
                           MessageBox.Show("unsuccessful")
                         
                        End Try

                    End If
                End If



            End With




        End Sub

    my app.config file

    <?xml version="1.0"?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
      </startup>
    </configuration>

     

    its run :)

  • 14 มกราคม 2555 20:00
    ผู้ดูแล
     
     

    Hello,

    I am surprised that in the books, it seems the treatement of exceptions is done like you did with the real advantage that you get an useless message "unsuccessful".

    The correct  treatement of exceptions is one of the part of an application which is maybe the most important one and if it is done in a clever way, it is really easy to find from where the error is coming

    The minimum is MessageBox.Show(ex.Message), afterwards , you may refine to get more informations making easier to find the cause of your error

     

    '''

    <summary>

     

    ''' Method treating a (generic) Exception

     

    '''

    </summary>

     

    ''' <param name="p_ex">System.Exception to treat

    </param>

     

    '''

    <remarks></remarks>

     

    Public Shared Sub TreatException(ByVal p_ex As Exception

    )

     

    Dim _ex As Exception =

    Nothing

     

    Dim p_i As Int32

    = 0

     

    Dim p_s As String = ""

    CommonCls.ErrorsCount += 1

     

     

    CommonCls.ShortMessage = "A (generic) Exception occured in " & CommonCls

    .ErrorPlace

    p_s =

    CommonCls.NowToString() & " **** (" & CommonCls

    .ErrorsCount.ToString()

    p_s &=

    ") " & CommonCls.ShortMessage & " **** " & CommonCls

    .Nl

    p_s &=

    "Message : " & p_ex.Message & CommonCls

    .Nl

    p_s &=

    "GetBaseException : " & p_ex.GetBaseException().GetType().FullName & CommonCls

    .Nl

    p_s &=

    " - Message : " & p_ex.GetBaseException().Message & CommonCls

    .Nl

    p_s &=

    " - Source : " & p_ex.Source & CommonCls

    .Nl

    p_s &=

    " - TargetSite : " & p_ex.TargetSite.Name & CommonCls

    .Nl

    p_s &=

    "Source : " & p_ex.Source & CommonCls

    .Nl

    p_s &=

    "TargetSite : " & p_ex.TargetSite.Name & CommonCls

    .Nl

    p_s &=

    "Data : "

     

    If ( p_ex.Data Is Nothing )

    Then

    p_s &=

    "N/A" & CommonCls

    .Nl

     

    Else

    p_s &=

    CommonCls

    .Nl

     

    For Each p_de As DictionaryEntry In

    p_ex.Data

    p_s &=

    " - Key : " & p_de.Key.ToString() & CommonCls

    .Nl

    p_s &=

    " - Value : " & p_de.Value.ToString() & CommonCls

    .Nl

     

    Next

     

    End

    If

    p_s &=

    "InnerException : "

     

    If ( p_ex.InnerException Is Nothing )

    Then

    p_s &=

    "N/A" & CommonCls

    .Nl

     

    Else

    p_s &=

    CommonCls

    .Nl

    _ex = p_ex.InnerException

     

    While ( Not ( _ex Is Nothing

    ) )

    p_s &=

    " - Inner" & p_i.ToString().PadRight(4) & " : " & CommonCls

    .Nl

    p_s &=

    " - Type : " & _ex.GetType().FullName & CommonCls

    .Nl

    p_s &=

    " - Message : " & _ex.Message & CommonCls

    .Nl

    p_s &=

    " - Source : " & _ex.Source & CommonCls

    .Nl

    p_s &=

    " - TargetSite: " & _ex.TargetSite.Name & CommonCls

    .Nl

    p_i += 1

    _ex = _ex.InnerException

     

    End

    While

     

    End

    If

    p_s &=

    "StackTrace " & CommonCls.Nl & p_ex.StackTrace & CommonCls

    .Nl

     

    CommonCls

    .ErrorMessage = p_s

     

    End

    Sub

     

     

    I give you the code i am using to treat an Exception error since 2003.It is working and it is giving enough informations to find the cause in less than 5 minutes ( The display of the StackTrace is useful as you have the exact linenumber where the exception occured in your code ). ErrorPlace should explain where the error/exception occured .ErrorMessage contains the error message built in this method.ErrorsCount  contains the total number of errors / exceptions which occured since the start of the application. Nl contains a NewLine used to format strings or error/short messages. ShortMessage contains the type of exception and the value of ErrorPlace

    As i am using VC{ ( 95% ) and VB (5%), i have decided to ignore the specific types of a language.Instead, i am using the .Net Framework types System.Int32 or Int32 instead of int in VC# or Integer in VB.So, i am sure that everybody could understand me.

    Instead ToDay which is specific to VB, use DateTime.Now, you are sure to be understood by everybody

    http://msdn.microsoft.com/en-us/library/system.datetime.now.aspx

    ToDay ignors the time part. If you use twice your application in the same day, you could have an exception the 2nd time ( the file exists already )

    I prefer to build my filename from DateTime.Now.ToString("yyyyMMdd_hhmmss"), you will get for example 20120830_140741 ( it is nearly the way that Microsoft builds the names of the install logs for SQL Server , why not to use a way that everybody can understand ) and you will obtain the different filename for each second  ( an unique value is sure except if you must throw your application every tenth of second ) 

    I would know what is the value contained in your filename from your SaveFileDialog1.I am not sure that this filename is without valid character

    We are waiting for your feedback to try to help you more efficiently

    Have a nice day

     

     


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
  • 16 มกราคม 2555 1:18
     
     

    Hello,

    I am surprised that in the books, it seems the treatement of exceptions is done like you did with the real advantage that you get an useless message "unsuccessful".

    The correct  treatement of exceptions is one of the part of an application which is maybe the most important one and if it is done in a clever way, it is really easy to find from where the error is coming

    The minimum is MessageBox.Show(ex.Message), afterwards , you may refine to get more informations making easier to find the cause of your error

     

    '''  

     

    <summary>

     

     

     

     

     

    ''' Method treating a (generic) Exception

     

     

     

    '''  

     

    </summary>

     

     

     

    ''' <param name="p_ex">System.Exception to treat

     

    </param>

     

     

     

    '''  

     

    <remarks></remarks>

     

     

     

    Public Shared Sub TreatException(ByVal p_ex As Exception

    )

     

     

     

    Dim _ex As Exception =  

     

    Nothing

     

     

     

    Dim p_i As Int32

    = 0

     

     

     

    Dim p_s As String = ""

    CommonCls.ErrorsCount += 1

     

     

    CommonCls.ShortMessage = "A (generic) Exception occured in " & CommonCls

    .ErrorPlace

    p_s =

     

     

    CommonCls.NowToString() & " **** (" & CommonCls

    .ErrorsCount.ToString()

    p_s &=

     

     

    ") " & CommonCls.ShortMessage & " **** " & CommonCls

    .Nl

    p_s &=

     

     

    "Message : " & p_ex.Message & CommonCls

    .Nl

    p_s &=

     

     

    "GetBaseException : " & p_ex.GetBaseException().GetType().FullName & CommonCls

    .Nl

    p_s &=

     

     

    " - Message : " & p_ex.GetBaseException().Message & CommonCls

    .Nl

    p_s &=

     

     

    " - Source : " & p_ex.Source & CommonCls

    .Nl

    p_s &=

     

     

    " - TargetSite : " & p_ex.TargetSite.Name & CommonCls

    .Nl

    p_s &=

     

     

    "Source : " & p_ex.Source & CommonCls

    .Nl

    p_s &=

     

     

    "TargetSite : " & p_ex.TargetSite.Name & CommonCls

    .Nl

    p_s &=

     

     

     

     

    "Data : "

     

     

     

    If ( p_ex.Data Is Nothing )  

     

    Then

     

     

    p_s &=

    "N/A" & CommonCls

    .Nl

     

     

     

     

     

    Else

     

     

    p_s &=

    CommonCls

    .Nl

     

     

     

    For Each p_de As DictionaryEntry In

    p_ex.Data

    p_s &=

     

     

    " - Key : " & p_de.Key.ToString() & CommonCls

    .Nl

    p_s &=

     

     

    " - Value : " & p_de.Value.ToString() & CommonCls

    .Nl

     

     

     

     

     

    Next

     

     

     

    End  

     

    If

     

     

    p_s &=

     

     

    "InnerException : "

     

     

     

    If ( p_ex.InnerException Is Nothing )  

     

    Then

     

     

    p_s &=

    "N/A" & CommonCls

    .Nl

     

     

     

     

     

    Else

     

     

    p_s &=

    CommonCls

    .Nl

    _ex = p_ex.InnerException

     

     

     

    While ( Not ( _ex Is Nothing

    ) )

    p_s &=

     

     

    " - Inner" & p_i.ToString().PadRight(4) & " : " & CommonCls

    .Nl

    p_s &=

     

     

    " - Type : " & _ex.GetType().FullName & CommonCls

    .Nl

    p_s &=

     

     

    " - Message : " & _ex.Message & CommonCls

    .Nl

    p_s &=

     

     

    " - Source : " & _ex.Source & CommonCls

    .Nl

    p_s &=

     

     

    " - TargetSite: " & _ex.TargetSite.Name & CommonCls

    .Nl

    p_i += 1

    _ex = _ex.InnerException

     

     

     

    End  

     

    While

     

     

     

    End  

     

    If

     

     

    p_s &=

    "StackTrace " & CommonCls.Nl & p_ex.StackTrace & CommonCls

    .Nl

     

     

     

    CommonCls

    .ErrorMessage = p_s

     

     

    End  

     

    Sub

     

     

     

     

     

    I give you the code i am using to treat an Exception error since 2003.It is working and it is giving enough informations to find the cause in less than 5 minutes ( The display of the StackTrace is useful as you have the exact linenumber where the exception occured in your code ). ErrorPlace should explain where the error/exception occured .ErrorMessage contains the error message built in this method.ErrorsCount  contains the total number of errors / exceptions which occured since the start of the application. Nl contains a NewLine used to format strings or error/short messages. ShortMessage contains the type of exception and the value of ErrorPlace

    As i am using VC{ ( 95% ) and VB (5%), i have decided to ignore the specific types of a language.Instead, i am using the .Net Framework types System.Int32 or Int32 instead of int in VC# or Integer in VB.So, i am sure that everybody could understand me.

    Instead ToDay which is specific to VB, use DateTime.Now, you are sure to be understood by everybody

    http://msdn.microsoft.com/en-us/library/system.datetime.now.aspx

    ToDay ignors the time part. If you use twice your application in the same day, you could have an exception the 2nd time ( the file exists already )

    I prefer to build my filename from DateTime.Now.ToString("yyyyMMdd_hhmmss"), you will get for example 20120830_140741 ( it is nearly the way that Microsoft builds the names of the install logs for SQL Server , why not to use a way that everybody can understand ) and you will obtain the different filename for each second  ( an unique value is sure except if you must throw your application every tenth of second ) 

    I would know what is the value contained in your filename from your SaveFileDialog1.I am not sure that this filename is without valid character

    We are waiting for your feedback to try to help you more efficiently

    Have a nice day

     

     


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.
    Thank you, successful and unsuccessful I've used here, the actual code in the different