|
Hi there .
A simple way to do this , just send and open empty connection in try catch block
Your connection string can looks like this following code :
<br />
private Boolean TestConnectionString()<br />
{<br />
string sqlServerDefaultConnectionString = "Data Source = (local) ; initial catalog = Master ; Integrated Security = true; ";<br />
<br />
SqlConnection sqlConnection = new SqlConnection();<br />
sqlConnection.ConnectionString = sqlServerDefaultConnectionString ;<br />
try<br />
{<br />
sqlConnection.Open();<br />
return true;<br />
}<br />
catch { return false; }<br />
finally <br />
{ <br />
if (!(sqlConnection == null)) <br />
{ sqlConnection.Close(); <br />
sqlConnection.Dispose();<br />
} <br />
}<br />
}<br />
<br />
DMASTER
|
|
|
|
|
That won't always work. What if there are no default instances of SQL Server installed. e.g. SQL Server 2005 Express Edition instals as an instance called SQLEXPRESS.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
hdv212 wrote: i want to create list of instance(s) of sql server that was installed on computer, how to do ?
This sample[^] may give you the hints that you need to get you on the right tracks.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
There is an article around here that shows how to get all the SQL Server instances on the visible network. Do a search in the C# database articles and you should be able to find it, since it is an app written in C#.
"The early bird may get the worm, but the second mouse gets the cheese" - anonymous, found in Uncle John's Bathroom Reader
|
|
|
|
|
Is it possible to work with generic collections in crystal report?
I defined a generic list like this:
List<Employee> employeeList = new List<Employee>();
And now I want to bind this collection with crystal report and I don't know how crystal report can work with this collection fields in my employee class .
If anybody know please explain in some example .
Thank you very much .
DMASTER
|
|
|
|
|
hi i just wana know the exe of search option present in start menu of windows XP
|
|
|
|
|
Hi,
the search facility in Windows Explorer does not have its own EXE; when you
start a search no new process gets launched. You can verify this with some
system observation tool such as TaskInfo. Hence the search code is part of
what is always loaded, probably explorer.exe itself.
|
|
|
|
|
Draw a fill box on screen. how can i get graphic object of screen or draw a box on screen?
thank you
|
|
|
|
|
Hi
You may use System.Drawing.Graphics and it have Drawline,DrawRectanle ...
|
|
|
|
|
I want to give information about my problem...
I want to build a properties form. When user click a control's properties menu item he/she can see the properties of that control in an other form and can change it at runtime. I have to do this form as a dll and call it from the exe application. What i want to dod is similar to Style Builder in Visual Web Developer. UI will change according to the selected control.
The objects i will work on is not visual studio objects they are different classes and different objects... and i have to get their properties at runtime these objects are not design time objects.
Could you please help me find an optimum solution of this problem.
thanks
-- modified at 3:36 Sunday 5th August, 2007
-- modified at 3:16 Monday 6th August, 2007
sniper47 Computer Engineer
|
|
|
|
|
In .Net you can use System.Windows.Forms.PropertyGrid and some attributes like System.ComponentModel.Browsable , System.ComponentModel.Description System.ComponentModel.DefaultValue and System.ComponentModel.Category for more control over the behavior of the object
how ever if you don't want to use PropertyGrid you can do it by your self using the Type class with methods such as GetProperties().
then you can invoke members here is for property
<br />
<br />
Type myType=myObject.GetType();<br />
System.Reflection.PropertyInfo pi=myType.GetProperty("address");<br />
pi.SetValue(myObject,"street",null);<br />
<br />
and I remember there was a PropertyGrid in vb6.0 if you don't use .Net
I hope the post would be useful
|
|
|
|
|
The objects i will work on is not visual studio objects they are different classes and different objects... and i have to get their properties at runtime these objects are not design time objects.
thank you for your interest
sniper47 Computer Engineer
|
|
|
|
|
Same thing applies. All you have to do is put a PropertyGrid control on your properties form, and then at runtime do:
propertyGrid1.SelectedObject=control; ...where control is the control whose properties you want to show up in the property grid. Then the user can edit the properties without any need for Visual Studio at all. Seems too good to be true, huh? But it is - try it out!
--Justin,
Microsoft MVP, C#
|
|
|
|
|
The below is my code which was written in Webservices. Once I compile it , the "not all code paths return a value" error occurs.
Give the solution of it.
[WebMethod]
public string GetFile(string fileName)
{
string strGetFile = "";
try
{
SPWeb site = new SPSite(srcUrl).OpenWeb();
SPFile spFile = site.GetFile(srcUrl + "/" + fileName);
if (spFile.Length > 0)
{
byte[] fileArray = new Byte[spFile.Length];
strGetFile = System.Text.ASCIIEncoding.ASCII.GetString(fileArray);
return strGetFile;
}
return strGetFile="";
}
catch {}
}
|
|
|
|
|
your method is not void and you didn't handle the catch clause code
[WebMethod]
public string GetFile(string fileName)
{
string strGetFile = "";
try
{
.
.
.
}
return strGetFile="";
}
catch {}//catch{return null;} or catch{throw new Exception("your Exception");}
}
good luck
|
|
|
|
|
The return value of your method is a string, which requires that all exit points from your method provide a value to satisfy the compiler. The following example derived from yours is marked up to show the exit points...
public string SomeMethod(string fileName)
{
string strGetFile = "";
try
{
strGetFile = "some file name";
...
return strGetFile; //==> your optional exit point
}
catch
{
strGetFile = "";
...
return strGetFile; //==> your optional exit point
}
return strGetFile; //==> the main and only required exit point
}
Another way to handle it is to use only one exit point (this makes it easier to maintain as typically multiple exit points generally result in an increase in software maintenance costs over time)...
public string SomeMethod(string fileName)
{
string strGetFile = "";
try
{
strGetFile = "some file name";
...
//ensure the string is set and simply leave the try
}
catch
{
strGetFile = ""; //or some error message
...
//ensure the string is set and simply leave the catch
}
//execution resumes here after the try/catch block
return strGetFile; //==> the main and only required exit point
}
John
|
|
|
|
|
i have 3 page
maste page
header page in side the master page
defalut page
now i want from the default page to change image in header page
how i can do this ??
Palestine
|
|
|
|
|
See the replies in the C# Web Development forum, and don't cross post, please
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I stand corrected
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Cool - but how did my post disappear?
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Whoa, beats me. I saw it myself earlier
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Today I ran into a problem with arraylists. And I can't seem to get why it doen't work. I have made the following function as below
When I use this function using statement A: result.Add(new string[] {subResult[0], subResult[1], subResult[2]}); I get this:
sr: rupert@doomsday.nl
sr: Rupert
sr: Monkey
sr: test@test.nl
sr: bart
sr: zuidgeest
rupert@doomsday.nl
test@test.nl
when I use statement B I get this output
sr: rupert@doomsday.nl
sr: Rupert
sr: Monkey
sr: test@test.nl
sr: bart
sr: zuidgeest
test@test.nl
test@test.nl
Notice the difference in the last two lines. Somehow when I use statement B I am left with only the second rusult in my arraylist twice instead of two different results. I need statement B because I cannot predict in advance what the amount of elements in each string array will be. Annyone want to tell me what's wrong? (Not that it should matter but this is on mono)
public ArrayList Search(string baseDN, int searchScope, string filter, string[] attributes)
{
ArrayList result = new ArrayList();
if (attributes == null || attributes.Length == 0)
{
return (result);
}
LdapSearchQueue queue = connection.Search ( baseDN, searchScope, filter, attributes, false, (LdapSearchQueue) null, (LdapSearchConstraints) null);
LdapMessage message;
string[] subResult = new string[attributes.Length];
while ((message = queue.getResponse()) != null)
{
if (message is LdapSearchResult)
{
int counter = 0;
LdapEntry entry = ((LdapSearchResult) message).Entry;
LdapAttributeSet attributeSet = entry.getAttributeSet();
foreach (string attributeName in attributes)
{
LdapAttribute attribute = attributeSet.getAttribute(attributeName);
subResult[counter] = attribute.StringValue;
counter++;
//Console.WriteLine("attr: " +attribute.StringValue + counter);
}
Console.WriteLine("sr: " + subResult[0]);
Console.WriteLine("sr: " + subResult[1]);
Console.WriteLine("sr: " + subResult[2]);
// A this works
//result.Add(new string[] {subResult[0], subResult[1], subResult[2]});
// B this doens't?
result.Add(subResult);
}
}
foreach(object a in result)
{
Console.WriteLine(((string[])a)[0]);
}
return(result);
}
|
|
|
|
|
That's not a mystery at all. It's a common mistake, and I believe that making it usually gives a better understanding about how objects and references work.
An ArrayList is a list of references.
With statement A you are creating a new array, and you add the reference to that array to the list. Each item in the ArrayList is a reference a separate array.
With statement B you are adding the reference in the subResult variable. As the variable never changes (only the contents of the array that it refers to), you end up with a list of references to the same single array, and that array happens to contain the last values that you put into it.
---
single minded; short sighted; long gone;
|
|
|
|
|
Ok, I entertained this posibility, But then I could not figure out why this does work:
ArrayList test = new ArrayList();
int[] numbers = new int[] {7,1};
test.Add(numbers);
numbers = new int[] {8,1};
test.Add(numbers);
foreach(object a in test)
{
Console.WriteLine(((int[])a)[0]);
}
this code gives me as result an 7 and then an 8 as I would expect .
But then I looked again and noticed the difference between this and my code is that I never create an new (string) array in my loop I just refill it. I should have noticed this an long time ago . I must realy like recreating objects. Tnanks Guffa for shaking me awake
|
|
|
|
|
hello
how can get pae name from URL
as this http://www.any.com/abc.aspx?ss=4
i want the result to be abc.aspx
????
Palestine
|
|
|
|