SQL connection works in forms application, but not asp.net

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltIFp5Y2g=?=, Nov 22, 2005.

  1. This function works in a Windows Forms .Net application, but when I try it in
    an ASP.Net application, I get an error:

    Cannot open database "codelib" requested by the login. The login failed.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information about
    the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: Cannot open database
    "codelib" requested by the login. The login failed.

    Function SqlTest() As String
    Dim cn As New OleDbConnection
    Dim cmd As New OleDbCommand
    Dim strConn As String
    Dim strSql As String
    strConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
    Security Info=False;Initial Catalog=codelib;Data
    Source=X3934834392\SQLEXPRESS;Use Procedure for Prepare=1;Auto
    Translate=True;Packet Size=4096;Workstation ID=X3934834392;Use Encryption for
    Data=False;Tag with column collation when possible=False"
    cn.ConnectionString = strConn
    cn.Open()
    strSql = "SELECT tblCode.title FROM tblCode WHERE tblCode.ID=" & 1 &
    ";"
    cmd = New OleDbCommand(strSql, cn)
    Return CStr(cmd.ExecuteScalar)
    End Function


    Does anybody know what I'm doing wrong or not doing?

    Thanks.
     
    =?Utf-8?B?VGltIFp5Y2g=?=, Nov 22, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?VGltIFp5Y2g=?=

    Bruce Barker Guest

    you connect string says to use trusted secuity. this means the asp.net
    application must run as a domain user with access to the database. in
    server2003, config the app pool, else the impersonate in the web config

    -- bruce (sqlwork.com)

    "Tim Zych" <> wrote in message
    news:...
    > This function works in a Windows Forms .Net application, but when I try it
    > in
    > an ASP.Net application, I get an error:
    >
    > Cannot open database "codelib" requested by the login. The login failed.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about
    > the error and where it originated in the code.
    >
    > Exception Details: System.Data.OleDb.OleDbException: Cannot open database
    > "codelib" requested by the login. The login failed.
    >
    > Function SqlTest() As String
    > Dim cn As New OleDbConnection
    > Dim cmd As New OleDbCommand
    > Dim strConn As String
    > Dim strSql As String
    > strConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
    > Security Info=False;Initial Catalog=codelib;Data
    > Source=X3934834392\SQLEXPRESS;Use Procedure for Prepare=1;Auto
    > Translate=True;Packet Size=4096;Workstation ID=X3934834392;Use Encryption
    > for
    > Data=False;Tag with column collation when possible=False"
    > cn.ConnectionString = strConn
    > cn.Open()
    > strSql = "SELECT tblCode.title FROM tblCode WHERE tblCode.ID=" & 1
    > &
    > ";"
    > cmd = New OleDbCommand(strSql, cn)
    > Return CStr(cmd.ExecuteScalar)
    > End Function
    >
    >
    > Does anybody know what I'm doing wrong or not doing?
    >
    > Thanks.
    >
     
    Bruce Barker, Nov 22, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?VGltIFp5Y2g=?=

    Rob Meade Guest

    "Tim Zych" wrote ...

    > Does anybody know what I'm doing wrong or not doing?


    A wild stab in the dark would perhaps be that maybe the website is using the
    IUSR_<computer-name> account for browsing, and as such does not carry with
    it any NT name used to log in to your database?

    Only a guess...

    Rob
     
    Rob Meade, Nov 22, 2005
    #3
  4. I'm using Forms Authentication, if that matters.

    I don't know how to implement any changes you mention. I'm using Windows 2000.

    thanks

    "Bruce Barker" wrote:

    > you connect string says to use trusted secuity. this means the asp.net
    > application must run as a domain user with access to the database. in
    > server2003, config the app pool, else the impersonate in the web config
    >
    > -- bruce (sqlwork.com)
    >
    > "Tim Zych" <> wrote in message
    > news:...
    > > This function works in a Windows Forms .Net application, but when I try it
    > > in
    > > an ASP.Net application, I get an error:
    > >
    > > Cannot open database "codelib" requested by the login. The login failed.
    > > Description: An unhandled exception occurred during the execution of the
    > > current web request. Please review the stack trace for more information
    > > about
    > > the error and where it originated in the code.
    > >
    > > Exception Details: System.Data.OleDb.OleDbException: Cannot open database
    > > "codelib" requested by the login. The login failed.
    > >
    > > Function SqlTest() As String
    > > Dim cn As New OleDbConnection
    > > Dim cmd As New OleDbCommand
    > > Dim strConn As String
    > > Dim strSql As String
    > > strConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist
    > > Security Info=False;Initial Catalog=codelib;Data
    > > Source=X3934834392\SQLEXPRESS;Use Procedure for Prepare=1;Auto
    > > Translate=True;Packet Size=4096;Workstation ID=X3934834392;Use Encryption
    > > for
    > > Data=False;Tag with column collation when possible=False"
    > > cn.ConnectionString = strConn
    > > cn.Open()
    > > strSql = "SELECT tblCode.title FROM tblCode WHERE tblCode.ID=" & 1
    > > &
    > > ";"
    > > cmd = New OleDbCommand(strSql, cn)
    > > Return CStr(cmd.ExecuteScalar)
    > > End Function
    > >
    > >
    > > Does anybody know what I'm doing wrong or not doing?
    > >
    > > Thanks.
    > >

    >
    >
    >
     
    =?Utf-8?B?VGltIFp5Y2g=?=, Nov 22, 2005
    #4
  5. I'm using Forms Authtication to log in.

    "Rob Meade" wrote:

    > "Tim Zych" wrote ...
    >
    > > Does anybody know what I'm doing wrong or not doing?

    >
    > A wild stab in the dark would perhaps be that maybe the website is using the
    > IUSR_<computer-name> account for browsing, and as such does not carry with
    > it any NT name used to log in to your database?
    >
    > Only a guess...
    >
    > Rob
    >
    >
    >
     
    =?Utf-8?B?VGltIFp5Y2g=?=, Nov 22, 2005
    #5
    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. Roy Lawson
    Replies:
    2
    Views:
    482
    Kevin Yu [MSFT]
    Feb 27, 2004
  2. Tim Zych
    Replies:
    0
    Views:
    350
    Tim Zych
    Nov 23, 2005
  3. Tim Zych
    Replies:
    2
    Views:
    515
    Tim Zych
    Nov 23, 2005
  4. John Kennedy
    Replies:
    5
    Views:
    244
    Carl Prothman [MVP]
    Aug 14, 2003
  5. John Kennedy
    Replies:
    5
    Views:
    458
    Carl Prothman [MVP]
    Aug 14, 2003
Loading...

Share This Page