How can ASPNET access the Northwind database

Discussion in 'ASP .Net' started by Tony Johansson, Jan 7, 2010.

  1. 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
    Tony Johansson, Jan 7, 2010
    #1
    1. Advertising

  2. 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.

    --
    Vapordan
    Shameless Author Plug
    ASP.NET 4 by Example only $20
    OWC Blackbook www.lulu.com/owc

    "Tony Johansson" <> wrote in message
    news:yxo1n.14423$...
    > 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
    >
    >
    Alvin Bruney - ASP.NET MVP, Jan 11, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bright
    Replies:
    2
    Views:
    4,015
    Bright
    Jul 16, 2005
  2. =?Utf-8?B?ZGVubmlzdDY4NQ==?=

    Can't open Northwind

    =?Utf-8?B?ZGVubmlzdDY4NQ==?=, Dec 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    5,714
    green apple
    Jun 26, 2009
  3. Harlan Messinger

    ASPNET won't connect to Northwind

    Harlan Messinger, Aug 26, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    458
    Harlan Messinger
    Aug 27, 2006
  4. Tony Johansson
    Replies:
    7
    Views:
    498
    Gregory A. Beamer
    Dec 23, 2009
  5. Harlan Messinger

    ASPNET won't connect to Northwind

    Harlan Messinger, Aug 26, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    5
    Views:
    172
    Harlan Messinger
    Aug 27, 2006
Loading...

Share This Page