|
Hi all
I use SQLEXPRESS and this is my connectionstring:
@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\\Data\\mydatabase.mdf;" + "Integrated Security=True;User Instance=True";
and i use sqlconnection to connect to my database.
and i execute my backup command like below:
string backup = string.Format("backup database mydatabase TO DISK= '{0}'", addr);
backup.ExecuteNonQuery();
but errormessage is :
Could not locate entry in sysdatabases for database 'mydatabase'. No entry found with that name. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
Changed database context to 'master'.
please somebody help me.
modified on Monday, December 14, 2009 4:15 AM
|
|
|
|
|
To backup and restore restore sql server, I would say make use of classes under SQLDMO namespace. Take a look at SQLServerClass class and the BackupClass class in that namespace. They offer required methods and properties.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
thx.
I want to know what is the required command for backup and restore?
I want to add a utility to my application that when user need a backup from database or restore to one of his backup databases , my application enable to do it.
|
|
|
|
|
There were previously a lot of Questions ask about this
http://www.codeproject.com/Messages/3119251/Re-back-up-sql-data-programmetically.aspx[^]
There are more just search the Forum for messages posted
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I use SQLEXPRESS and this is my connectionstring:
@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\\Data\\mydatabase.mdf;" + "Integrated Security=True;User Instance=True";
and i use sqlconnection to connect to my database.
and i execute my backup command like below:
string backup = string.Format("backup database mydatabase TO DISK= '{0}'", addr);
backup.ExecuteNonQuery();
but errormessage is :
Could not locate entry in sysdatabases for database 'mydatabase'. No entry found with that name. Make sure that the name is entered correctly.
BACKUP DATABASE is terminating abnormally.
Changed database context to 'master'.
please somebody help me.
|
|
|
|
|
Repeating the same question as if you did not hear the response will not get you further response.
except this one, of course!
|
|
|
|
|
If you pay more attention i modified my question !
I want to know that can i backup from mydatabase in SQLEXPRESS by the code that i notice?
|
|
|
|
|
Because there is no database with the name 'mydatabase' the syntax of the backup database is incorrect. Here are two Sp's use them
For Backup
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- backup a database
ALTER PROCEDURE [dbo].[sp_BackupDatabase]
@databasename varchar(32),
@path varchar(256),
@filename varchar(64)
AS
set nocount on
declare @sql varchar(4000)
select @sql = 'BACKUP DATABASE ' + ltrim(rtrim( @databasename ))
select @sql = @sql + ' TO DISK = ''' + ltrim(rtrim(@path)) + ltrim(rtrim(@filename)) + ''' '
select @sql = @sql + ' WITH INIT'
--print @sql
execute ( @sql )
select 'Database successfully backed up!' [Result]
and later you might want to Restore and you can use this
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sp_RestoreDatabase]
@dbname char(32), -- the database name to restore as
@filename char(64), @path char(256) -- the location of the backuped up database file (on the SQL Server)
AS
set nocount on
declare @sql nvarchar(3000)
-- Restore the database
select @sql = ' RESTORE DATABASE ' + ltrim(rtrim( @dbname )) + ' FROM DISK = ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @filename )) + ''' '
select @sql = ltrim(rtrim(@sql)) + ' WITH '
select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name
select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name
select @sql = ltrim(rtrim(@sql)) + ' ,REPLACE,RECOVERY;'
--select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name
--select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name
print @sql
execute ( @sql )
-- Was the command successful or was there a problem
if ( (select @@Error) = 0 ) begin
-- Put an entry into oDirect.dbo.tbl_dbRef
-- execute ( 'sp_DataSet_Save ''' + @xml + ''' ' )
-- TODO: restore the users
select 'Restore Successful' [Result]
end
else begin
select 'Restore Unsuccessful' [Result]
end
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
what is the diffrennce between String & string
|
|
|
|
|
There are no differences. string is an alias for String [^].
Some people use String when they are accessing the String class and string when they are declaring a constant.
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
String comes from the .NET class System.String and string (lower case) is a
C# alias for System.String.
|
|
|
|
|
Hi ,
What is the difference between static,readonly and constant
Thanks and advance,
Azeez.
|
|
|
|
|
constant is constant
static is static
readonly is readonly.
Honestly, wikipedia isn't available in your native tongue? Or is the first chapter of your book to difficult...
|
|
|
|
|
There are pleny of links available on the internet.
Here - try this one [^].
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
EliottA wrote: Honestly, wikipedia isn't available in your native tongue?
Don't you trust MSDN?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
d@nish wrote: Don't you trust MSDN?
Never a good sign, it it ?
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
Static : - Which shared the value with multiple instance
Readonly :- once define.. you can change the value through constructor only at the time of creating instance..
<br />
Constant :- once define; you can't change it,,
|
|
|
|
|
Hi ,
When we have to use abstract and when we have to use interface in real time coding
Thanks in advance
Azeez.
|
|
|
|
|
Interface is lightweight than Abstract....
<br />
Abstract <br />
When you don't clear about the future expansion of the framework... <br />
For creating multiple version application..<br />
For creating products...<br />
For putting common behavior so that drived classes can use it without writing code again & again...
Interface<br />
For defining rules and business policies...<br />
To enforce something....<br />
to overcome the problem of multiple inhetitence
|
|
|
|
|
You never have to use either.
When defining a group of similar classes you may find it beneficial to define an interface (or more than one) that specifies what things the classes have in common.
If there is some common code that the classes should share, you may want to put that code in a base class. If that base class itself should not be instantiated, then you may want to mark it as abstract.
In the long run, you probably should always define an interface whenever you define a base class.
|
|
|
|
|
There are some thousands of xmlfiles i want to have from internet, but instead of downloading them one by one, is it possible to build an application that can do that for me?
Exempelfile: http://somedomain.com/XmlResults/Id=100
so, from id=100 it goes up 1 step upto id=10000 and each step is 1 xmldocument
if someone know how i should start to build it, it would be nice to hear from you.
Thanks!!
|
|
|
|
|
So you need to create a loop that increments the ID value and executes the download.
Look into while or for loops
Use the string object to modify the request statement
string sFile = string.format{"http//somedomain....{0}",ID);
I suggest getting a book on basic C# programing and work through the examples, learning from forum posts is not really a good idea.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you!
So why having a forum if i cant learn from here??
I got books but for me its difficult to understand.
this is what i got now, loop is working good but i cant download more than 1 of the files to my hard drive.
for (int i = 3483; i < 3583; i++)
{
string sFile = string.Format("http://www.svenskaspel.se/includes/xmlelements/XMLresultat.asp?produktid=1&omgang={0}", +i);
XmlDocument doc = new XmlDocument();
doc.Load(sFile);
doc.Save(Application.StartupPath + "/test.xml");
}
Whats the other options for download Xmldocuments to hd?
Can Save method download more than 1 at the time?
|
|
|
|
|
When I do something simple like:
double result = 3.1 * 4.1;
I get the result = 12.709999999999999;
Is this to be expected for such a simple calculation??
|
|
|
|
|