473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with C# code

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\d bConnection.cs(21):
Unreachable code detected
x:\Projects\Programs\c#.net\SpxConnectionStrings\d bConnection.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\d bConnection.cs(26): The
name 'If' does not exist in the class or namespace
'SpxConnectionStrings.dbConnection'
x:\Projects\Programs\c#.net\SpxConnectionStrings\d bConnection.cs(37):
Unreachable code detected
Any ideas?

Thanks

Jul 21 '05 #1
3 3547

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
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.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Jul 21 '05 #2
Hi,
After removing the semi-colon I get the only error

D:\Projects\Programs\c#.net\SpxConnectionStrings\d bConnection.cs(27): ;
expected
and thats at the end of the 'if' where I removed the semi-colon.

"Peter van der Goes" wrote:

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:C1**********************************@microsof t.com...
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.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Jul 21 '05 #3

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...
Hi,
After removing the semi-colon I get the only error

D:\Projects\Programs\c#.net\SpxConnectionStrings\d bConnection.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;
}

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
6
by: Mark Reed | last post by:
Hi all, I am trying to learn a little about programming (I know next to nothing so far) and have found some code which hides the toolbars. However, this bit of code is a little too effective and...
4
by: dixie | last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I have just installed HTML Help in an application. I told it in the Project Properties the path to the help file. I then...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
16
by: Allen | last post by:
I have a class that returns an arraylist. How do I fill a list box from what is returned? It returns customers which is a arraylist but I cant seem to get the stuff to fill a list box. I just...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
1
by: glenn123 | last post by:
Hi, i am just about out of time to produce a working jukebox which has to perform these functions: to play music files when a track is chosen from a list which when the user presses the change genre...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.