Connecting to SQL Server on WIN2003 Box

G

Guest

I am trying to connect to a 2003 Server from an ASP.Net page and am getting
the following error message. Can someone please help get me started on how to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist or
access denied. at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in c:\documents and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 
A

Arild Bakken

Verify that you can connect using the specified username and password in SQL
Query Analyzer.

I assume the server is setup with both SQL and Integrated login enabled and
that you have created the specified login in the SQL server and granted the
login access to the given database?

Also, to make sure you can connect, try from a command prompt on the
webserver to telnet to port 1433 (if TCP/IP is the transport you're using).


Regards,

Arild
 
G

Guest

The server is set for both SQL and integrated login. I'm not sure how to use
a command prompt to telnet to port 1433. If you can help with that, I'll give
it a try.

Here is other information that I forgot earlier.
1. I am trying to connect from a Windows XP Professional computer.
2. Currently the server is both a web and database server using Win 2003.
3. We are trying to develop on our XP boxes and test items before moving the
pages over to the test server.

Thanks

Arild Bakken said:
Verify that you can connect using the specified username and password in SQL
Query Analyzer.

I assume the server is setup with both SQL and Integrated login enabled and
that you have created the specified login in the SQL server and granted the
login access to the given database?

Also, to make sure you can connect, try from a command prompt on the
webserver to telnet to port 1433 (if TCP/IP is the transport you're using).


Regards,

Arild

Mike Collins said:
I am trying to connect to a 2003 Server from an ASP.Net page and am getting
the following error message. Can someone please help get me started on how
to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist or
access denied. at
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in c:\documents
and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Mike,

The issue arises from the fact that you are running with default
credentials in ASP.NET. By default, all code that runs in ASP.NET runs
under the ASPNET local user. This doesn't have access to network resources.

In order to get around this, you have to impersonate a user (through
code, or through a declaration in web.config) which has rights to the
network, and to SQL Server.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mike Collins said:
The server is set for both SQL and integrated login. I'm not sure how to
use
a command prompt to telnet to port 1433. If you can help with that, I'll
give
it a try.

Here is other information that I forgot earlier.
1. I am trying to connect from a Windows XP Professional computer.
2. Currently the server is both a web and database server using Win 2003.
3. We are trying to develop on our XP boxes and test items before moving
the
pages over to the test server.

Thanks

Arild Bakken said:
Verify that you can connect using the specified username and password in
SQL
Query Analyzer.

I assume the server is setup with both SQL and Integrated login enabled
and
that you have created the specified login in the SQL server and granted
the
login access to the given database?

Also, to make sure you can connect, try from a command prompt on the
webserver to telnet to port 1433 (if TCP/IP is the transport you're
using).


Regards,

Arild

Mike Collins said:
I am trying to connect to a 2003 Server from an ASP.Net page and am
getting
the following error message. Can someone please help get me started on
how
to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist or
access denied. at
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in
c:\documents
and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 
A

Arild Bakken

To try connecting to the server using telnet:

1. Start a command prompt (Start / Run / type "cmd" and press enter).
2. Type: telnet TestWebServer 1433

This only works if the server is configured to use TCP/IP and only if the
SQL server instance is using port 1433 - you can check that on the server
using the SQL server configuration tool.

Another thing, is the SQL instance the default instance or is it a named
instance? If it is a named instance you need to include the instance name in
the server name, like servername\instancename.


Arild

Mike Collins said:
The server is set for both SQL and integrated login. I'm not sure how to
use
a command prompt to telnet to port 1433. If you can help with that, I'll
give
it a try.

Here is other information that I forgot earlier.
1. I am trying to connect from a Windows XP Professional computer.
2. Currently the server is both a web and database server using Win 2003.
3. We are trying to develop on our XP boxes and test items before moving
the
pages over to the test server.

Thanks

Arild Bakken said:
Verify that you can connect using the specified username and password in
SQL
Query Analyzer.

I assume the server is setup with both SQL and Integrated login enabled
and
that you have created the specified login in the SQL server and granted
the
login access to the given database?

Also, to make sure you can connect, try from a command prompt on the
webserver to telnet to port 1433 (if TCP/IP is the transport you're
using).


Regards,

Arild

Mike Collins said:
I am trying to connect to a 2003 Server from an ASP.Net page and am
getting
the following error message. Can someone please help get me started on
how
to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist or
access denied. at
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in
c:\documents
and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 
W

Willy Denoyette [MVP]

On W2K3 aspnet runs as NETWORK_SERVICE, not as aspnet.

Willy.

Nicholas Paldino said:
Mike,

The issue arises from the fact that you are running with default
credentials in ASP.NET. By default, all code that runs in ASP.NET runs
under the ASPNET local user. This doesn't have access to network
resources.

In order to get around this, you have to impersonate a user (through
code, or through a declaration in web.config) which has rights to the
network, and to SQL Server.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mike Collins said:
The server is set for both SQL and integrated login. I'm not sure how to
use
a command prompt to telnet to port 1433. If you can help with that, I'll
give
it a try.

Here is other information that I forgot earlier.
1. I am trying to connect from a Windows XP Professional computer.
2. Currently the server is both a web and database server using Win 2003.
3. We are trying to develop on our XP boxes and test items before moving
the
pages over to the test server.

Thanks

Arild Bakken said:
Verify that you can connect using the specified username and password in
SQL
Query Analyzer.

I assume the server is setup with both SQL and Integrated login enabled
and
that you have created the specified login in the SQL server and granted
the
login access to the given database?

Also, to make sure you can connect, try from a command prompt on the
webserver to telnet to port 1433 (if TCP/IP is the transport you're
using).


Regards,

Arild

I am trying to connect to a 2003 Server from an ASP.Net page and am
getting
the following error message. Can someone please help get me started on
how
to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist
or
access denied. at
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in
c:\documents
and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 
W

Willy Denoyette [MVP]

Set your connection string to use integrated security, and add NETWORK
SERVICE as a user and grant appropriate rights.
NT AUTHORITY\NETWORK USER is the the default user running aspnet.
Note that I noticed that you are running IIS and SQL on the same box (W2K3),
above is only applicable in such configuration.

Willy.
 
G

Guest

Thanks to all of you for your input. I'm going to look into adding rights in
webconfig. I'll make another post, in a couple of days, if I need further
assistance. Thanks again.

Arild Bakken said:
To try connecting to the server using telnet:

1. Start a command prompt (Start / Run / type "cmd" and press enter).
2. Type: telnet TestWebServer 1433

This only works if the server is configured to use TCP/IP and only if the
SQL server instance is using port 1433 - you can check that on the server
using the SQL server configuration tool.

Another thing, is the SQL instance the default instance or is it a named
instance? If it is a named instance you need to include the instance name in
the server name, like servername\instancename.


Arild

Mike Collins said:
The server is set for both SQL and integrated login. I'm not sure how to
use
a command prompt to telnet to port 1433. If you can help with that, I'll
give
it a try.

Here is other information that I forgot earlier.
1. I am trying to connect from a Windows XP Professional computer.
2. Currently the server is both a web and database server using Win 2003.
3. We are trying to develop on our XP boxes and test items before moving
the
pages over to the test server.

Thanks

Arild Bakken said:
Verify that you can connect using the specified username and password in
SQL
Query Analyzer.

I assume the server is setup with both SQL and Integrated login enabled
and
that you have created the specified login in the SQL server and granted
the
login access to the given database?

Also, to make sure you can connect, try from a command prompt on the
webserver to telnet to port 1433 (if TCP/IP is the transport you're
using).


Regards,

Arild

I am trying to connect to a 2003 Server from an ASP.Net page and am
getting
the following error message. Can someone please help get me started on
how
to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist or
access denied. at
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in
c:\documents
and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 
G

Guest

I'm confused. If the connection string is specifying "User
Id=sa;Password=sa_password", then why in all of creation is ASP.NET sending
credentials as ASPNET and not "sa"? What's the point in having SQL
credentials if you can't use them?

Willy Denoyette said:
Set your connection string to use integrated security, and add NETWORK
SERVICE as a user and grant appropriate rights.
NT AUTHORITY\NETWORK USER is the the default user running aspnet.
Note that I noticed that you are running IIS and SQL on the same box (W2K3),
above is only applicable in such configuration.

Willy.

Mike Collins said:
I am trying to connect to a 2003 Server from an ASP.Net page and am getting
the following error message. Can someone please help get me started on how
to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist or
access denied. at
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in c:\documents
and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 
W

Willy Denoyette [MVP]

Did I say that you can't use them?
I only said that in a configuration that runs SQL and IIS (aspnet) on the
same box, you better use integrated security.
Note that from this code

SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
it's impossible for us to tell whether the specified credentials are correct
or that the Servername is correct, so to eliminate the credentials as a
possible cause, specify integrated security.


Note that, whatever the configuration is, you should always prefer
integrated security over explicit hard coded user credentials, especially
sa credentials.

Willy.


Nate said:
I'm confused. If the connection string is specifying "User
Id=sa;Password=sa_password", then why in all of creation is ASP.NET
sending
credentials as ASPNET and not "sa"? What's the point in having SQL
credentials if you can't use them?

Willy Denoyette said:
Set your connection string to use integrated security, and add NETWORK
SERVICE as a user and grant appropriate rights.
NT AUTHORITY\NETWORK USER is the the default user running aspnet.
Note that I noticed that you are running IIS and SQL on the same box
(W2K3),
above is only applicable in such configuration.

Willy.

Mike Collins said:
I am trying to connect to a 2003 Server from an ASP.Net page and am
getting
the following error message. Can someone please help get me started on
how
to
track and fix this error? The code I am using is below the error I am
getting.

Error: System.Data.SqlClient.SqlException: SQL Server does not exist or
access denied. at
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction) at
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString
options, Boolean& isInTransaction) at
System.Data.SqlClient.SqlConnection.Open() at
testbed.Navigation.Page_Load(Object sender, EventArgs e) in
c:\documents
and
settings\collinss\vswebcache\605webdev-2_443\testbed\navigation.aspx.cs:line
31

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SqlDataReader dataReader = null;

try
{
SqlConnection connection = new
SqlConnection("Server=TestWebServer;Database=Common;user id=myUserID;
password=myPassword");
SqlCommand command = new SqlCommand("GetNavigationMenu", connection);
command.CommandType = CommandType.StoredProcedure;
connection.Open();
dataReader = command.ExecuteReader();

while (dataReader.Read())
{
string headerMenu = (string)dataReader["HeaderMenu"];
string sectionID = (string)dataReader["SectionID"];
string navigationMenuID = (string)dataReader["NavigationMenuID"];
string menuName = (string)dataReader["MenuName"];
string pageUrl = (string)dataReader["PageUrl"];
string ImageUrl = (string)dataReader["ImageUrl"];
}

dataReader.Close();
connection.Close();
}

catch (System.Exception exception)
{
Response.Write("Error: " + exception.ToString());
return;
}

finally
{
if (dataReader != null)
{
dataReader.Close();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top