|
I have used it for new Databases. Worked fine!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
can backup work fine after attach database to server, i have attached database to server but it is not finding the database file name.
Regards
Narendra Singh
(Jindal Tech Ventures)
|
|
|
|
|
I am at the moment searching my own code for suitable example. Will get back to you in a while.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
ok i m waiting for your positive reply, one more thing can we call sp_attach_db stored procedure programatically
Regards
Narendra Singh
(Jindal Tech Ventures)
|
|
|
|
|
Here is a snippet which doesn't use sp_attach_db, since it seems to be giving you some problems.
public static void AttachDatabase(Server server)
{
string databaseName;
StringCollection dbFiles = new StringCollection();
Dialogs.DBFilesDialog dbfd = new Dialogs.DBFilesDialog();
if (dbfd.ShowDialog() == DialogResult.OK)
{
dbFiles.Add(dbfd.PrimaryFileName);
dbFiles.AddRange(dbfd.DataFiles);
dbFiles.AddRange(dbfd.LogFiles);
databaseName = dbfd.DatabaseName;
if ((dbFiles[0] != null) && (dbFiles[0] != string.Empty))
{
if (MessageBox.Show(@"Do you really want to Attach the " + dbFiles[0] +
@" database?", Application.ProductName, MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.No)
{
return;
}
server.AttachDatabase(databaseName, dbFiles, AttachOptions.RebuildLog);
}
}
}
The server object is an instance of the Server class from the Microsoft.SqlServer.Management.Smo namespace.
Dialogs.DBFilesDialog is a self built Dialog which simply enables the user to select the primary files and log files for the database in one place. Basically it is two ListBoxes, each with an associated button which, when clicked, presents an OpenFileDialog filtered for *.mdf and *.ldf respectively. It has properties for the Primary File name (string), DataFiles (string[]) and LogFiles (string[]).
The code is from a VS2005 SQLUtilities library of mine but should translate directly to VS2008(10?) with no problems.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
thanks henry for your precious code but i m using object database not smo
Regards
Narendra Singh
(Jindal Tech Ventures)
|
|
|
|
|
It's a pleasure.
Good luck.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi..
I am new to this forum..
Please assist me on the issue im facing..
I have created a virtual directory programmatically using C#. It works fine. The thing is i had a folder named "Service" inside the virtual directory. I have to set anonymous access property = true for this particuar folder..
Thanks in Advance..
Regards,
Maha
|
|
|
|
|
|
Thanks for your reply..
These links shows how to create virtual directory thro C#.. and will set anonymous acess=true for all the folders inside the website..
But i need to set this property for a single folder inside the site...
|
|
|
|
|
I got a streamreader which read a text file(txtfile1) which contain thing like
THIS IS LINE
THIS IS LINE 2
THIS IS LINE 3
Now i got a streamwriter which write the txtfile1 into textfile2.
textfile2 will also have
THIS IS LINE
THIS IS LINE 2
THIS IS LINE 3
So i asking here how do i remove the extra line between "THIS IS LINE" and "THIS IS LINE 2".
|
|
|
|
|
If the line you read with your streamreader is a blank line then just don't write it with your streamwriter . Like this
StreamReader sr = new StreamReader(@"C:\YourFile.txt");
StreamWriter sw = new StreamWriter(@"C:\YourNewFile.txt");
string line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
if (line != string.Empty)
sw.WriteLine(line);
}
sw.Close();
modified on Monday, April 26, 2010 6:17 AM
|
|
|
|
|
thanks alot Calla. i used your code and it work well.
|
|
|
|
|
You're welcome!
|
|
|
|
|
Hi Rikq,
while((strdata = sr.ReadLine())!=null)
{
if(strdata == null || strdata == string.Empty)
continue;
//write into file
}
hope this could help you.
Regards
Surender
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
surender.m wrote: if(strdata == null || strdata == string.Empty)
You do realize there is a method available for this, string.IsNullOrEmpty or string.IsNullOrWhiteSpace in 4.0
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark,
I hav given him basic idea on how to accomplish it.
However string.isnullorempty is not availabe in 1.1 , it is included from 2.0 version.
Regards
Surender
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
surender.m wrote:
<pre lang="text">
while((strdata = sr.ReadLine())!=null)
{
if(strdata == null
</pre>
Why test for null twice?
|
|
|
|
|
Hi ,
I do agree, there is no need to check for null again.
I would suggest this
while((strdata = sr.ReadLine())!=null)
{
if(strdata.Trim().Length == 0)
continue;
}
wht would you say.
regards,
Surender
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
Yeah, that's pretty much what <i>I</i> do.
|
|
|
|
|
While reading your text file search for the new line character '\n'.
If you find this character, ignore reading this line.
|
|
|
|
|
depends on your definition of "blank line". Do you realy want to throw away a line holding a couple of spaces and/or tabs?
|
|
|
|
|
If you decide to use the suggestions made by others you might consider replacing
<br />
if(strdata == null || strdata == string.Empty)<br />
by
<br />
if (string.IsNullOrEmpty(strdata))<br />
It does the same thing, albeit 15 milliseconds more slowly, but IMHO it reads more easily.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: if(strdata == null || strdata == string.Empty)
wasn't a very good suggestion as the two cases need to be handled differently; a null indicates the end of the stream, whereas string.Empty is a line the OP wants to skip.
Henry Minute wrote: albeit 15 milliseconds more slowly
so you did manage to run .NET on that 66MHz i8088 system of yours after all?
|
|
|
|
|
Luc Pattyn wrote: wasn't a very good suggestion as the two cases need to be handled differently;
A valid point. However where legitimately testing for null or empty I still prefer IsNullOrEmpty().
Luc Pattyn wrote: so you did manage to run .NET on that 66MHz i8088 system of yours after all?
That wasn't the hard part. Getting it to run under Windows 3.1 was more problematic.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|