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

T

Tim Zych

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.
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top