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

Discussion in 'ASP .Net' started by Tim Zych, Nov 23, 2005.

  1. Tim Zych

    Tim Zych Guest

    I'm trying to connect to a SQL Server (Express) database with an Asp.Net
    solution that currently uses MS Access. I want to replace it with SQL
    Server.

    I got a rudimentary prototope to work in a .Net Forms application, but when
    I try to connect to the database from ASP.Net, 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.
    -----

    Here's the function. I pulled the connection string out of the data
    connection that Visual Studio.Net created when I added a new connection. I
    do not know if this is the proper connection string. It worked for the Forms
    app, but I do not know what must be done to get it to work for Asp.Net.

    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

    Is there a tutorial that can walk me through step by step how to connect to
    SQL Server via ASP.Net? Or can someone please help me to get this to work?
    This is an ASP.Net application that uses simple Forms authentication.

    thanks for any help.

    This is a 2nd post based on an earlier post. I got some replies that look
    like they pointed in a direction in a macro way, but I do not know how to
    implement them.
     
    Tim Zych, Nov 23, 2005
    #1
    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:
    489
    Kevin Yu [MSFT]
    Feb 27, 2004
  2. =?Utf-8?B?VGltIFp5Y2g=?=

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

    =?Utf-8?B?VGltIFp5Y2g=?=, Nov 22, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,198
    =?Utf-8?B?VGltIFp5Y2g=?=
    Nov 22, 2005
  3. Tim Zych
    Replies:
    2
    Views:
    518
    Tim Zych
    Nov 23, 2005
  4. John Kennedy
    Replies:
    5
    Views:
    263
    Carl Prothman [MVP]
    Aug 14, 2003
  5. John Kennedy
    Replies:
    5
    Views:
    469
    Carl Prothman [MVP]
    Aug 14, 2003
Loading...

Share This Page