How can ASPNET access the Northwind database

T

Tony Johansson

Hello!!

I use IIS 5 and SQL Server Express 2005
Acccount ASPNET is used when running IIS to access the SQL Server database.
This account ASPNET get access to the database server by using the
BUILTIN\user login account.

Now if I look at Security->users that have access to the Northwind database
I
can find these four accounts.
dbo
guest
INFORMATION_SCHEMA
sys.

The owner of the Northwind database is Tony.
There is no user called ASPNET under Security->users for the Northwind
database.

Here is quick and dirty code that show how I connect to the northwind
database.
After this code can you see the web.config file

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection sqlConn = null;
try
{
ConnectionStringSettings cs =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"];
string connString = cs.ConnectionString;
sqlConn = new SqlConnection(connString);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = "select user_name(), current_user";
sqlCmd.Connection = sqlConn;
sqlConn.Open();
string svar = (string)sqlCmd.ExecuteScalar();
Response.Write(svar);
}
catch (Exception)
{
throw;
}
}

web.config file
***********
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;
Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;"
providerName="System.Data.SqlClient" />

<add name="NorthwindConnectionString" connectionString="Data
Source=HEMPC\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
<authorization>
<allow users="John"/>
<deny users="?"/>
</authorization>
<authentication mode="Forms">
<forms loginUrl="LoginForm.aspx" timeout="5" cookieless="AutoDetect"
protection="All"/>
</authentication>
<compilation debug="true"/>
</system.web>
</configuration>

Can somebody explain how ASPNET can get access rights to the Northwind
database ?
I don't understand how ASPNET can access the Nortwind database.


//Tony
 
A

Alvin Bruney - ASP.NET MVP

Integrated Security=True
meaning your login information on the machine you signed in, will be used to
pass to northwind. In your Northwind db, you should grant access to the
identity that you use to log on to the machine. If you do that step
properly, it will show up as a 5th account in the Northwind db.
 

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

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top