473,320 Members | 1,810 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.

SQL Connection Error

I am trying to connect to a SQL server that is on a different machine
in the building. I can view the contents in Enterprise Manager and
Query Analyzer. The problems arise when I try to connect to this
database from a web application. Apparently I need an actual login and
password on the SQL server for connecting from a web application. Is
this always the case or are there ways around this. If it means
anything, I am using Visual Studio .NET 2003 and have imported all
relevant (I believe so) namespaces for this to work.

Connection string:

<add key="SQLConnection" value="Data Source=ServerName;Initial
Catalog=DatabaseName />
Testing connectivity:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Try

Dim objSQLConn As New
SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("SQLConnection"))
objSQLConn.Open()
If objSQLConn.State = ConnectionState.Open Then
Label1.Text = "SQL Connection is open"
Else
Label1.Text = "SQL Connection is closed"
End If

Catch sqlxcp As SqlClient.SqlException
Label2.Text = sqlxcp.ToString
Label3.Text = sqlxcp.Message
Label4.Text = sqlxcp.Source
Label5.Text = sqlxcp.Number
Finally
End Try

End Sub
______________________

I can view the data just fine in VS .NET's dataset filler but when I go
to actually connect via web application I get a plethora of errors. Any
suggestions?

Nov 19 '05 #1
10 1334
I guess I should probably provide the errors:

Login failed for user '(null)'. Reason: Not associated with a trusted
SQL Server connection.

..Net SqlClient Data Provider

18452

I can view the SQL server tables and data just fine using my Windows NT
account but not when I try to connect from a web application. Any
suggestions?

Nov 19 '05 #2
You do need to include a username and password unless you want to add
ASPNET account to SQL Server (not recommended by me). Right now you are
telling SQL to use a Trusted Connection (default if not specified).

your connection string might look like this:
data source=(LOCAL);initial catalog=YourDataBase;uid=UserName;pwd=Password;
Clint Hill
H3O Software
http://www.h3osoftware.com
Sparky Arbuckle wrote:
I am trying to connect to a SQL server that is on a different machine
in the building. I can view the contents in Enterprise Manager and
Query Analyzer. The problems arise when I try to connect to this
database from a web application. Apparently I need an actual login and
password on the SQL server for connecting from a web application. Is
this always the case or are there ways around this. If it means
anything, I am using Visual Studio .NET 2003 and have imported all
relevant (I believe so) namespaces for this to work.

Connection string:

<add key="SQLConnection" value="Data Source=ServerName;Initial
Catalog=DatabaseName />
Testing connectivity:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Try

Dim objSQLConn As New
SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("SQLConnection"))
objSQLConn.Open()
If objSQLConn.State = ConnectionState.Open Then
Label1.Text = "SQL Connection is open"
Else
Label1.Text = "SQL Connection is closed"
End If

Catch sqlxcp As SqlClient.SqlException
Label2.Text = sqlxcp.ToString
Label3.Text = sqlxcp.Message
Label4.Text = sqlxcp.Source
Label5.Text = sqlxcp.Number
Finally
End Try

End Sub
______________________

I can view the data just fine in VS .NET's dataset filler but when I go
to actually connect via web application I get a plethora of errors. Any
suggestions?

Nov 19 '05 #3
Thanks for the reply Clint.

I am running this app from my inetpub folder until I am able to upload
it to a web server. I want to test everything first. I tried adding
uid and pwd to my connection string and now I am getting the error:

Login failed for user 'UserName'.

..Net SqlClient Data Provider

18456

In VS when I right-click the adapter to preview dataset for this
connection I can view just fine so I know I'm able to connect to this
database. My windows authentication is what I used to connect to the
SQL server via Enterprise manager and Query Analyzer. This works
flawlessly. The only problem is when I try and connect via web app.

Does this make sense or do I need to clarify more?

Nov 19 '05 #4
You have two things conflicting that are confusing you.

You can connect to SQL using Windows Auth, (through VS.NET). You cannot
connect (as you have found) through your Web app. The reason is the web
app is running under an account IUSR_YOURSERVERNAME that uses ASPNET
account. This account doesn't have permissions to your SQL Server. You
can add it and assign it permissions in your database, but I wouldn't
recommend this.

I would however recommend creating a new SQL Server user and add it to
the database you are connecting to. Then use that username and password
in your connection string. You can also test this when using Server
Explorer in VS.NET
Clint Hill
H3O Software
http://www.h3osoftware.com
Sparky Arbuckle wrote:
Thanks for the reply Clint.

I am running this app from my inetpub folder until I am able to upload
it to a web server. I want to test everything first. I tried adding
uid and pwd to my connection string and now I am getting the error:

Login failed for user 'UserName'.

.Net SqlClient Data Provider

18456

In VS when I right-click the adapter to preview dataset for this
connection I can view just fine so I know I'm able to connect to this
database. My windows authentication is what I used to connect to the
SQL server via Enterprise manager and Query Analyzer. This works
flawlessly. The only problem is when I try and connect via web app.

Does this make sense or do I need to clarify more?

Nov 19 '05 #5
When you running VS.NET, you are running it as you. So the database
connections go through as you. Integrated security works.

When you run a web page, ASP.NET does *not* run as you, just because you are
the one who requested the page. It runs as the ASPNET user (or some other
user if you changed this setting). So if ASPNET (or the other user) does
not have access to the database, then you get this error.

'UserName' was an example he gave. Meaning you need to replace it with a
real user name on your sql server, and same thing goes for the password.
Unless you happen to have a user called 'UserName' with a password
'Password' - which I highly doubt anyone would.

I recommend you do some googling around for information on ASP.NET's
security model and how it related to ADO.NET.
"Sparky Arbuckle" <tw*@secureroot.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Thanks for the reply Clint.

I am running this app from my inetpub folder until I am able to upload
it to a web server. I want to test everything first. I tried adding
uid and pwd to my connection string and now I am getting the error:

Login failed for user 'UserName'.

.Net SqlClient Data Provider

18456

In VS when I right-click the adapter to preview dataset for this
connection I can view just fine so I know I'm able to connect to this
database. My windows authentication is what I used to connect to the
SQL server via Enterprise manager and Query Analyzer. This works
flawlessly. The only problem is when I try and connect via web app.

Does this make sense or do I need to clarify more?

Nov 19 '05 #6
I just realized that you can add this to your web config:

<identity impersonate="true">

This would force ASPNET to use your Windows Account. then your sql
connection string can stay as you had it. However, then, each person
connecting to your database will need a Windows Account on the SQL
Server and associated to the database.
Clint Hill
H3O Software
http://www.h3osoftware.com
Sparky Arbuckle wrote:
Thanks for the reply Clint.

I am running this app from my inetpub folder until I am able to upload
it to a web server. I want to test everything first. I tried adding
uid and pwd to my connection string and now I am getting the error:

Login failed for user 'UserName'.

.Net SqlClient Data Provider

18456

In VS when I right-click the adapter to preview dataset for this
connection I can view just fine so I know I'm able to connect to this
database. My windows authentication is what I used to connect to the
SQL server via Enterprise manager and Query Analyzer. This works
flawlessly. The only problem is when I try and connect via web app.

Does this make sense or do I need to clarify more?

Nov 19 '05 #7
You 2 make so much sense that it's ridiculous. Thanks a million Clint &
Marina!

Nov 19 '05 #8
When I add identity impersonate="true" I get:

Login failed for user '\'.

Nov 19 '05 #9
My guess is that you have anonymous access turned on for the web
application and your application cannot retrieve a value of the
AUTH_USER server variable. Try turning anonymous access off in your web
app and see if that works.

However, you'll definitely want to change this before moving your
application into production as every user of your application would
need to have access to the SQL Server. As is mentioned in the thread
above, setting up a specific SQL Server login account and using that
username and password is the best means of creating dependable and
secure access to the database from your web application.

HTH

Thanks,
Denny Boynton

Nov 19 '05 #10
On 16 Aug 2005 10:36:55 -0700, "Sparky Arbuckle" <tw*@secureroot.com> wrote:

¤ I am trying to connect to a SQL server that is on a different machine
¤ in the building. I can view the contents in Enterprise Manager and
¤ Query Analyzer. The problems arise when I try to connect to this
¤ database from a web application. Apparently I need an actual login and
¤ password on the SQL server for connecting from a web application. Is
¤ this always the case or are there ways around this. If it means
¤ anything, I am using Visual Studio .NET 2003 and have imported all
¤ relevant (I believe so) namespaces for this to work.
¤

Some pieces of information need to be confirmed here. What level of authentication are you using for
your web app? Anonymous? Basic? Integrated Windows?

If SQL Server is not installed on your web server you cannot delegate security when your web
application is configured for Integrated Windows security w/o configuring your environment for
Kerberos.

There are alternative solutions, such as using Basic authentication, but we would need to know what
type of security you need for your web application.

You may also want to view the following document:

http://msdn.microsoft.com/library/de...delegation.asp
Paul
~~~~
Microsoft MVP (Visual Basic)
Nov 19 '05 #11

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

Similar topics

2
by: wolverine1654 | last post by:
I have an application that we are moving to a 2003 server using IIS6. Currently, it works fine with IIS5 on a NT server. When I try to log into the application and connect to an Oracle DB, I get...
1
by: Mark Day | last post by:
Hi All, I have an application that links tables to an ODBC source. The DSN parameters are obtained from a custom .ini file. An incorrect DSN string gives the user a 'friendly' connection error...
1
by: PJ | last post by:
I'm getting an error message when posting information from my asp page to the database. This is the error message: DODB.Connection error '800a0e7c' Parameter object is improperly defined....
1
by: Agnes | last post by:
I got sql statment "select a,,,,,,z from myTable " (26 fields, 4 fields 's size is nvarchar(200) ) When the table got over 5000 records and I want to fill in the dataset. It will show "internal...
0
by: rhepsi | last post by:
Dear All, Im vb.net 1.1, When im trying to update the records from mysql to postgresql, the connection error: the following code is Update data button click: Dim myPgrConnect As...
5
by: icegray | last post by:
Hi, I am new about C# and MS SQL. I have done a new program which use MS SQL Database and I've install it to a new computer. But program doesn't run on new computer. I give SQL Server Connection...
0
by: =?Utf-8?B?UmljaGFyZCBC?= | last post by:
We have been receiving a connection error at one of our sites, our application works elsewhere. The error occurs when our application written in vb.net 2.0 running as a Windows Service under the...
2
sonu5588
by: sonu5588 | last post by:
I am facing problem in connection. This code is OK , when i Deploy or Create a EXE of this project and install it on other system then the connection error generates, whats the solution to create a...
3
by: mvjohn100 | last post by:
When I found " Too many connection error" may occur because of mysql default allowed maximum connection of 100. I changed it to a big value. but even my fedora shows the same error what are the...
0
by: cwinay | last post by:
Hi, I'm using hibernate, mysql 5.0.22 and struts 2 in my application. In struts2, I'm using REST plugin and classes that extends ActionSupport and implements ModelDriven interface (webservice...
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...
1
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.