|
I have had this error on several occasions, all of them could be traced to my having incorrect parameters in the connection string. Not always the same parameter though.
So check the connection string for correctness.
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.”
|
|
|
|
|
Something to check before trying other things, open the Sql Server Configuration Manager, go to Protocols and ensure TCP/IP is enabled. It isn't by default...
Regards,
Rob Philpott.
|
|
|
|
|
are u trying to connect to a web database such as MySql on wwww.example.com?
|
|
|
|
|
Hello,
How i can search for a particular gif file (and open it) in a particular directory. I need the search to be recusive, i mean there are many folders in this directory and in each directory other folder and so on. I need the program to search in all those directories for this file.
How can i do it?
|
|
|
|
|
string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.gif",
SearchOption.AllDirectories);
I know nothing , I know nothing ...
|
|
|
|
|
lol... bit too easy for my liking
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Stark DaFixzer wrote: SearchOption.AllDirectories
Not seen that before and have always written a recursive procedure for this sort of thing. Does this work?
Regards,
Rob Philpott.
|
|
|
|
|
I agree with musefan LOL... but yep, it does work
|
|
|
|
|
Yes it works.
There are some disadvantages: it will search all before it returns anything. (And the results may be huge).
.NET 4.0 will offer some new methods, enumerating while searching, rather than building an array.
And a limitation: it only works well as long as a single filter is all you need.
Finding all BMP, GIF, PNG, JPEG would need many of those (resulting in a different order), or another tactic.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Luc Pattyn wrote: Yes it works.There are some disadvantages: it will search all before it returns anything.
Yes that is right !!
I know nothing , I know nothing ...
|
|
|
|
|
Yep. I use it in a homebaked app to catalog my <ahem> picture collection.
Mike Devenney
|
|
|
|
|
michaelgr1 wrote: How can i do it?
See here[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
well like you said, write a recursive function. Basic idea...
using System.IO;
string FindFile(string initDirectory, string fileToFind)
{
DirectoryInfo dir = new DirectoryInfo(initDirectory);
foreach(FileInfo file in dir.GetFiles())
{
if(file.Name == fileToFind)
return file.FullName;
}
foreach(DirectoryInfo subDir in dir.GetDirectories())
{
return FindFile(subDir.FullName, fileToFind);
}
return null;
}
..that should do the trick, if not I hope you get the idea
Life goes very fast. Tomorrow, today is already yesterday.
modified on Friday, May 29, 2009 9:03 AM
|
|
|
|
|
Hello,
This code gives me the following errors:
Error Cannot convert to static type 'System.IO.Directory'
Error Cannot convert type 'System.IO.DirectoryInfo' to 'System.IO.Directory'
Error The name 'FindFile' does not exist in the current context
Error 'System.IO.Directory' does not contain a definition for 'Fullpath'
|
|
|
|
|
see edited code... thou you should have been able to fix those mistakes yourself. The error messages are very straight forward.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I'm sorry,
I fixed those errors myself , but it still doesn't work properly as i need.
it enters only the subdirectories of the first directory (in the initdirectory) and so on.
If i have many directories in the main directory (initdirectory) and so on in the other subdirectories it doesn't work.
Of course if the file is located somewhre there in the subdirectories of the subdirectories...
|
|
|
|
|
hmmm.. post the code you are using
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I used exactly the code you wrote.
but it doesn't searches in the directories as i need (as i wrote in the previous post)
|
|
|
|
|
Also i tries this way-
private void dirsearch(string Start_dir, string search)
{
MessageBox.Show(search);
try
{
foreach (string d in Directory.GetDirectories(Start_dir))
{
MessageBox.Show(d);
foreach (string f in Directory.GetFiles(Start_dir))
{
if (f.Contains(search))
{
if (!f.Contains(".doc"))
Process.Start(f);
review_file_found = true;
}
}
dirsearch(d, search);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
But it doesn't find the file as well (but seems that search ok- in the sub-directories)
|
|
|
|
|
what string are you passing in as the file to find?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
for example;
061_pmr_c0_txhb_cut_rxhb_to_smx.vl.GIF
|
|
|
|
|
Just open visual studio 2005 / latest
add
one button (to intiate click event ),
one textbox (contains expression you want to search ),
and one listbox to show the results
add click event on Button1 by double clicking on it and paste following code
//replace mine path with your own
DirectoryInfo DirInfo = new DirectoryInfo(@"F:\Documents and Settings\Administrator\My Documents\");
FileInfo[] DirFiles = DirInfo.GetFiles(textBox1.Text, SearchOption.AllDirectories);
listBox1.Items.Clear();
foreach (FileInfo FileObj in DirFiles)
{
listBox1.Items.Add(FileObj);
}
goto top of file and add a namespace >> using System.IO;
press F5 and run
insert expression to search. click on button. result will be displayed to list box.
if this doesnot work the provide me email address i will mail my project to you
|
|
|
|
|
Why you didn't use my code ? (The first Comment ?)
No offense , it's just a kind of discussion ...
thank you ...
I know nothing , I know nothing ...
|
|
|
|
|
Hello,
I tried many ways to do it (as you wrote and another ways) but in all of them it doesn't always find the file i need.
For example if the starting path is the immediate folder that contains the file it works fine and finds the file, but when the starting patch is a higher (maybe 2-3 folder upper) it doesn't find this file (i write exactly the same name).
It seems it doesn't enough time to the program to collect all the files names inside the folder. I did a little delay but it didn't help.
This is my code:
foreach (string d in Directory.GetDirectories(Start_dir))
{
if (!d.Contains("Shared Documents"))
{
System.Threading.Thread.Sleep(200);
foreach (string f in Directory.GetFiles(d))
{
//MessageBox.Show(f);
if (f.Contains(search))
{
Process.Start(f);
review_file_found = true;
return;
}
}
dirsearch(d, search);
}
}
|
|
|
|
|
Or it even seems as it doesn't have enough memory to do this search.
Because files (in directories) that are located in the "beginning of the list" it finds (and opens),
But files that are located a little "deeper" in the list he can't file and even the application get stucked in such situations
|
|
|
|