problem connecting to SQL Server

  • Thread starter Thread starter Greg Bahns
  • Start date Start date
G

Greg Bahns

I am having a strange problem connecting to a SQL Server 2000 database from
an ASP.NET application.

The strange thing is that I can connect fine using ADODB in an old-fashioned
ASP application, but I get the message "SQL Server does not exist or access
denied" when I try to connect using the SqlConnection object in an ASP.NET
C# application running on the same machine.

The database is SQL Server 2000 running on Windows Server 2003, and the
development machine is running Windows XP with VS.NET 2003, .NET Framework
1.1.

The database server is named "mydbserver", and the developer machine is
named "mywebserver".

Here is the connection string from the old ASP application:
Provider=SQLOLEDB;Server=mydbserver;Initial
Catalog=Contacts;Trusted_Connection=Yes

Here is the connection string from the new ASP.NET application:
workstation id=mywebserver;packet size=4096;integrated security=SSPI;data
source=mydbserver;persist security info=False;initial catalog=Contacts;

I should also point out that I have no trouble connecting from the VS.NET
environment itself, under the Data Connections subtree in the Server
Explorer pane. The ASP.NET connection string above was generated
automatically for me when I added a SqlConnection object in the designer, so
you would think it would work.

From this I would guess that there's some configuration that's wrong, but
I've tried a number of things and numerous MSDN and google searches with no
luck. I'm hoping someone here can help.

Thanks,
Greg
 
Hi Greg,

Since ASP.NET application runs under very restricted aspnet windows account
it has no privileges to access network plus the account is local to your
computer.

The solutions would be:
- use Sql server authenticaton
- run your application under different account
 
Thanks for your reply.

I forgot to mention that I am running both the ASP and the ASP.NET
applications under the same account.

I began to wonder if setting the account under the Directory Security tab in
the IIS console applies to ASP.NET, and it this point I'm not sure.

Now I have specified the account using the identity tag in web.config. I'm
now pretty certain that it's running under the desired account, because when
I change the password, the ASP.NET application returns the appropriate
error.

Unfortunately, when I set it all up and try again, I still get the "SQL
Server does not exist or access denied" error.

One more note: this error is returned after 15 seconds, which is the default
connection timeout. This fact seems consistent with "server not found" as
opposed to "access denied".

Thanks,
Greg
 
Hi Gred,

Does your account have network privileges?
What happens if you switch to sql server authentiacation?
 
Miha,

I did finally get it working, but I'm confused about it.

Previously, I had added "Network Library=DBMSSOCN" to the
connection string. At some point after that, I added the
identity tag in web.config to ensure that it was running
under the desired account. After removing the Network
Library setting, then it started working. I don't
understand this because I thought DBMSSOCN was the
default, so it shouldn't have made a difference, and
either way I think it should have worked that way.

Also, since in the identity element I specified the same
account that was specfied in the IIS Console, this seems
to imply that the IIS setting was having no effect. Does
that sound right?

Any insight would be appreciated, although at this point
I'm just happy that it's working.

Thanks,
Greg
 
Hi,

Greg Bahns said:
Miha,

I did finally get it working, but I'm confused about it.

Previously, I had added "Network Library=DBMSSOCN" to the
connection string. At some point after that, I added the
identity tag in web.config to ensure that it was running
under the desired account. After removing the Network
Library setting, then it started working. I don't
understand this because I thought DBMSSOCN was the
default, so it shouldn't have made a difference, and
either way I think it should have worked that way.

Also, since in the identity element I specified the same
account that was specfied in the IIS Console, this seems
to imply that the IIS setting was having no effect. Does
that sound right?

Yup, I think that identity is managed by app (web.config or perhaps
machine.config or impersonation in code).
Any insight would be appreciated, although at this point
I'm just happy that it's working.

Dont' touch it then :)
I normally drag & drop a connection in designer or use ConnectString
property (if you choose new from drop down list) to build my connection
string. Then I copy/paste it to wherever I need it.
Probably it wasn't working with DBMSSOCN becuase it seems that it is
necessary only when working with TCP/IP address, example:
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN
 
Back
Top