Connecting to a remote sql server

F

Frank Schumacher

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
 
M

Michal Boleslav Mechura

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 Grüße nach Leipzig,
Michal
 
B

bruce barker

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)


| 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
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top