|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello !
I have an vb.net 2013 application that use a SQL server database.
Currently I'm using sql server 2008R2.
To Backup / restore database from vb.net I'm using SMO.
But the problem is that when I try my application on sql server 2012 , the backup / restore functions doesn't work anymore , because the SMO files that my application use are for sql server 2008R2.
So I'm thinking is there any way to Backup restore a database that is independent from SQL server version ?
Thank you !
|
|
|
|
|
Create a backup script and execute it?
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
|
The simplest script would be like
BACKUP DATABASE MySQLDatabase
TO DISK = "C:\backups\MySQLDatabase.bak";
You can execute this against your database connection, after changing the database name and file location of the backup file to match your own values.
There are quite a few options to the BACKUP command, but this shows the absolute simplest case. For more details, have a look here:[^]
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
The SMO-libraries are for a specific version of SQL Server. You can use the backup and restore -commands without SMO. That way it should be possible to restore your backup on a newer (!) version of SQL Server. AFAIK, it doesn't work the other way around.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you !
But as I'm comfortable using SMO , is there any way to keep in different fodders , SMO files for a specific version of SQL server, and to alter when I need ? ( just an idea , I don't know if this can work ).
|
|
|
|
|
I'd recommend against using SMO for operations that can be performed using native SQL commands, as it adds a dependency to a specific version of SQL Server. It is also a lot easier to change a SQL-script when there's a need due to difference between versions.
Yes, it is possible to use "all" the SMO libraries, for each different version - but that is definitely not easier; first of all, you'd need to link to various libraries containing the same types and classes, which is something that is usually not done as it creates conflicts.
You could prevent so by loading the library dynamically, using reflection to do what you want - which adds more complexity. Alternative, you decompile the SMO-assemblies and stitch them together into a new one.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Can you give me some help , or where can I read more about Loading the library dynamically ?
Thank you !
|
|
|
|
|
Loading stuff using reflection is not explained in a single post, it is a complete topic by itself. There's articles on CodeProject like "Reflection in .NET[^]", and an article from Visual Studio Magazine[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
It cannot be done by simply replacing the assembly, nor by mapping it.
Hence, the recommendation for SQL.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You need to listen to what is being said here, there is a difficult way of doing things, SMO and swapping libraries, and there is an easy way of doing things, TSQL and a stored procedure/query.
If you insist on going down the difficult path then you need to do a shed load of research while reading the recommended article on TSQL should be relatively simple.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to know the algorithm for balancing chemical equations
|
|
|
|
|
|
This does not even appear to be a programming question.
|
|
|
|
|
Hello !
I don't want all the items that a default textbox's context menu contains.
So I'm using a custom context menu :
Dim contextMenu = New ContextMenu()
contextMenu.MenuItems.Add(New MenuItem("Copy", Sub(s, ea) textBox1.Copy()))
contextMenu.MenuItems.Add(New MenuItem("Paste", Sub(s, ea) textBox1.Paste()))
contextMenu.MenuItems.Add(New MenuItem("Undo", Sub(s, ea) textBox1.Undo()))
contextMenu.MenuItems.Add(New MenuItem("Select All", Sub(s, ea) textBox1.SelectAll()))
textBox1.ContextMenu = contextMenu
But the problem is that now , all these commands are always enabled even in some cases when shouldn't be. for example even nothing is copied , the Paste command is enabled. Event the textbox is empty and nothing is selected , the Copy command is enabled.
----Is there a way to fix this behavior ?
----Or maybe is there a way to not use a custom menu . but just to hide the items that I don't want in the default context menu , using TextBox.ConTextMenu.Popup event ?
Thank you !
|
|
|
|
|
It is not a paste-command; it is a menu-item that executes code. If you want to enable the menu-item, you can do so, but then you'd need to keep a reference to the item.
satc wrote: Is there a way to fix this behavior ? It is not a bug; if you want the behaviour, you'll have to build it.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You need to check each time before the context menu is shown what conditions exist, and set each item to enabled or disabled as appropriate.
|
|
|
|
|
So , I think it's better to consider the second solution , so to leave the contextmenu as default (not using a custom menu ) but just hide some items and leave those that I want , using ContextMenu.Popup. Is that possible ?
|
|
|
|
|
|
I tried a quick Google search on modifying the standard ContextMenu-popup and it doesn't look like there's an easy solution to this.
However, I think building your own and checking the conditions for enabling/disabling the menu entries isn't as difficult as you might think. Take a look at the Clipboard[^]-class - there are easy to use methods to check if and what the clipboard contains, e.g. Clipboard.ContainsText(). Combined with the sample Richard linked for you it should be rather straight forward.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Thank you!
Using Clipboard class I have resolved the most of the problems.
The only menu items that remain is Undo.
What should I check inside the ContextMenu.Popup event , in order to determine that this command should be enable or disable ?
|
|
|
|
|
In both WPF[^] and Windows Forms[^], the TextBox control has a CanUndo property.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hey,
I don't know if you mean you want a code example for disabling the buttons in your Context Menu or your code doesn't work.
If your code doesn't work as it suppose to do just try this (after you disabled for example a button in your context menu):
YourControlName.Refresh
If you mean that you don't have a code, I have a good example.
Private Sub EditPaste_Click(sender As Object, e As EventArgs) Handles EditPaste.Click
Dim iData As IDataObject = Clipboard.GetDataObject()
If iData.GetDataPresent(DataFormats.Text) Then
TextEditorBox.SelectedText = CType(iData.GetData(DataFormats.Text), String)
End If
End Sub
Private Sub EditCut_Click(sender As Object, e As EventArgs) Handles EditCut.Click
If TextEditorBox.SelectedText <> "" Then
Clipboard.SetText(TextEditorBox.SelectedText)
TextEditorBox.SelectedText = ""
Else
MsgBox("Nothing selected")
End If
End Sub
Private Sub EditCopy_Click(sender As Object, e As EventArgs) Handles EditCopy.Click
If TextEditorBox.SelectedText <> "" Then
Clipboard.SetText(TextEditorBox.SelectedText)
Else
MsgBox("Nothing selected")
End If
End Sub
Hopefully your question is awnsered
|
|
|
|