Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Connecting to a remote sql server

Reply
Thread Tools

Connecting to a remote sql server

 
 
Frank Schumacher
Guest
Posts: n/a
 
      01-27-2005
Hi NG,

I try to connect to a remote MS-SQL-Server 2000 from an ASP.NET
application. Here's how I do it:

private void ConnectToDatabase(string host, string dataBaseName, string
userID, string password)
{
string connectionString;

connectionString = "Initial Catalog=" + dataBaseName + ";";
connectionString += "Data Source=" + host + ";";
connectionString += "Integrated Security=SSPI;";
connectionString += "User ID=" + userID + ";";
connectionString += "Password=" + password + ";";

_myConnection = new SqlConnection();
_myConnection.ConnectionString = connectionString;
try
{
_myConnection.Open();
}
catch (Exception e)
{
throw e;
}
}

If I use this module in a windows-gui c# project, it works fine. But in
an ASP.NET application I get the error: Login failed for user
'domainname\computername$'
I have double checked User ID and Password in the connetion string, but
they were correct.

Any ideas on that?

Thanks,
Frank
 
Reply With Quote
 
 
 
 
Michal Boleslav Mechura
Guest
Posts: n/a
 
      01-27-2005
I see from your code that you are using SQL Server's integrated security. It
means that SQL Server uses the account under which the application is
running, and not the user ID and password quoted in the connection string,
to decide whether it will let it in or not.

ASP.NET applications run under a local machine account named ASPNET. You
need to give this account the necessary rights. If your database were
located on the same computer as the executable then I'd advise you to make
the account a member of the Administrators" group. But since your database
is located on a remote computer, I'm not sure what would be the best thing
to do. Maybe impersonation?

Viele Gre nach Leipzig,
Michal

--
Michal Boleslav Mechura
http://www.velocityreviews.com/forums/(E-Mail Removed)

"Frank Schumacher" <(E-Mail Removed)-leipzig.de> wrote in message
news:%(E-Mail Removed)...
> Hi NG,
>
> I try to connect to a remote MS-SQL-Server 2000 from an ASP.NET
> application. Here's how I do it:
>
> private void ConnectToDatabase(string host, string dataBaseName, string
> userID, string password)
> {
> string connectionString;
>
> connectionString = "Initial Catalog=" + dataBaseName + ";";
> connectionString += "Data Source=" + host + ";";
> connectionString += "Integrated Security=SSPI;";
> connectionString += "User ID=" + userID + ";";
> connectionString += "Password=" + password + ";";
>
> _myConnection = new SqlConnection();
> _myConnection.ConnectionString = connectionString;
> try
> {
> _myConnection.Open();
> }
> catch (Exception e)
> {
> throw e;
> }
> }
>
> If I use this module in a windows-gui c# project, it works fine. But in an
> ASP.NET application I get the error: Login failed for user
> 'domainname\computername$'
> I have double checked User ID and Password in the connetion string, but
> they were correct.
>
> Any ideas on that?
>
> Thanks,
> Frank



 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      01-27-2005
because you set integrated security on in the connection string, the
user/password setting are ignored, they are for sqlserver's standard
security. the webconfig supports setting the nt user account and password,
see <identity impersonate="true" username='domain\user" password="password"
/>

-- bruce (sqlwork.com)


"Frank Schumacher" <(E-Mail Removed)-leipzig.de> wrote in message
news:%(E-Mail Removed)...
| Hi NG,
|
| I try to connect to a remote MS-SQL-Server 2000 from an ASP.NET
| application. Here's how I do it:
|
| private void ConnectToDatabase(string host, string dataBaseName, string
| userID, string password)
| {
| string connectionString;
|
| connectionString = "Initial Catalog=" + dataBaseName + ";";
| connectionString += "Data Source=" + host + ";";
| connectionString += "Integrated Security=SSPI;";
| connectionString += "User ID=" + userID + ";";
| connectionString += "Password=" + password + ";";
|
| _myConnection = new SqlConnection();
| _myConnection.ConnectionString = connectionString;
| try
| {
| _myConnection.Open();
| }
| catch (Exception e)
| {
| throw e;
| }
| }
|
| If I use this module in a windows-gui c# project, it works fine. But in
| an ASP.NET application I get the error: Login failed for user
| 'domainname\computername$'
| I have double checked User ID and Password in the connetion string, but
| they were correct.
|
| Any ideas on that?
|
| Thanks,
| Frank


 
Reply With Quote
 
Frank Schumacher
Guest
Posts: n/a
 
      01-28-2005
Thanks Bruce and Michal,
that has done it

Ciao,
Frank

bruce barker wrote:
> because you set integrated security on in the connection string, the
> user/password setting are ignored, they are for sqlserver's standard
> security. the webconfig supports setting the nt user account and password,
> see <identity impersonate="true" username='domain\user" password="password"
> />
>
> -- bruce (sqlwork.com)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to remote connect to the SQL server 2005 when th ere is a‘\’ in the SQL server name, such as 192.168.0.1 1\active? Wesley Chen Ruby 9 04-14-2009 11:36 AM
How to remote connect to the SQL server 2005 when th ere is a‘\’ in the SQL server name, such as 192.168.0.1 1\active? Wesley Chen Ruby 0 04-07-2009 10:23 AM
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com ASP .Net 0 05-03-2008 12:43 PM
connecting vs 2005 to remote SQL server 2000 Me LK ASP .Net 3 11-04-2007 10:34 AM
trouble connecting to remote SQL server for authentication brian.newman@wpafb.af.mil ASP .Net 2 10-26-2006 01:55 PM



Advertisments