Help with C# code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have the foll code in a class.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Security.Principal;


namespace SpxConnectionStrings
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class dbConnection
{
public SqlConnection Get()
{
//
// TODO: Add constructor logic here
//
if (false)
{
return null;
}

WindowsIdentity CallersIdentity = windowsIdentity.GetCurrent();

If (CallersIdentity.IsAuthenticated == false);
{

return null;

}





string myConnectionString = "Initial Catalog=Northwind;Data
Source=xx.xx.xx.xx;Integrated Security=SSPI;";



SqlConnection myConnection = new
SqlConnection(myConnectionString);
return myConnection;


}
}
}

I get the following error when I compile the project



D:\Projects\Programs\c#.net\SpxConnectionStrings\dbConnection.cs(21):
Unreachable code detected
x:\Projects\Programs\c#.net\SpxConnectionStrings\dbConnection.cs(24): The
type or namespace name 'windowsIdentity' could not be found (are you missing
a using directive or an assembly reference?)
x:\Projects\Programs\c#.net\SpxConnectionStrings\dbConnection.cs(26): The
name 'If' does not exist in the class or namespace
'SpxConnectionStrings.dbConnection'
x:\Projects\Programs\c#.net\SpxConnectionStrings\dbConnection.cs(37):
Unreachable code detected


Any ideas?

Thanks
 
Chris said:
Hi,
I have the foll code in a class.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Security.Principal;


namespace SpxConnectionStrings
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class dbConnection
{
public SqlConnection Get()
{
//
// TODO: Add constructor logic here
//
if (false)
{
return null;
}

WindowsIdentity CallersIdentity = windowsIdentity.GetCurrent();

If (CallersIdentity.IsAuthenticated == false);
{

return null;

}
<snip>
See the semi-colon at the end of the if statement? That's a null statement
that is the one statement controlled by the if.
 
Hi,
After removing the semi-colon I get the only error

D:\Projects\Programs\c#.net\SpxConnectionStrings\dbConnection.cs(27): ;
expected


and thats at the end of the 'if' where I removed the semi-colon.
 
Chris said:
Hi,
After removing the semi-colon I get the only error

D:\Projects\Programs\c#.net\SpxConnectionStrings\dbConnection.cs(27): ;
expected


and thats at the end of the 'if' where I removed the semi-colon.
OK, what about the typos?

WindowsIdentity CallersIdentity = windowsIdentity.GetCurrent(); // lower
case w?

If (CallersIdentity.IsAuthenticated == false); // upper case i in if?
{

return null;

}

And last, what is this code supposed to do?
if (false)
{
return null;
}
 
Back
Top