473,654 Members | 3,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.Ole Db.OleDbExcepti on: 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=SQLOL EDB.1;Integrate d Security=SSPI;P ersist
Security Info=False;Init ial Catalog=codelib ;Data
Source=X3934834 392\SQLEXPRESS; Use Procedure for Prepare=1;Auto
Translate=True; Packet Size=4096;Works tation ID=X3934834392; Use Encryption
for
Data=False;Tag with column collation when possible=False"
cn.ConnectionSt ring = strConn
cn.Open()
strSql = "SELECT tblCode.title FROM tblCode WHERE tblCode.ID=" & 1 &
";"
cmd = New OleDbCommand(st rSql, cn)
Return CStr(cmd.Execut eScalar)
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.


Nov 23 '05 #1
2 950
In your connectionstrin g i do not see the userid and password attribute
-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

Nov 23 '05 #2
It's the same connection string that worked for the windows forms.

I tried entering the password and userid, which actually I don't have one
because SQL Server is using Windows Authentication, and got the same error.
<sh**********@y ahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
In your connectionstrin g i do not see the userid and password attribute
-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3301
by: Dmitry Karneyev | last post by:
Hi All! I've got an ado.net app with several win forms. In the first form (form1) I connect to DB and in other forms I use connection string generated by the form1 and stored in sqlconnection object of form1. If I use windows authorization of SQL Server everything works fine, but when I use SQL Server authorization it doesn't work because sqlconnection object doesn't store the password and as a result of retrieving connection string...
10
2703
by: Brian Conway | last post by:
I have no idea what is going on. I have a Login screen where someone types in their login information and this populates a datagrid based off of the login. Works great in debug and test through VS, however, when I change to release and put it out on the web it fails giving me the following error message The underlying connection was closed. Could not establish a trust relationship with the remote server.
4
17650
by: refer_to_website | last post by:
How can I use the Server.MapPath(".") value inside of the web.config? For example, when I add the following just before the </configuration>, and run via CTRL-F5, I receive error The '&' character, hexadecimal value 0x26, cannot begin with a name. <appSettings> <add key="ConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(".") & "DATABASE\test.mdb;" />
1
1205
by: toke | last post by:
I've build a DLL in VB.net that handles all sorts of business logic. This DLL accecesses a SQL server for some data in the following way: <Begin pseudo-code snip> Open a Connection Con = new Connection (bla bla bla arguments) 'Make recordset 1 (using stored procedures, but only containing "select" commands) rs1 = new recordset
26
16499
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On Win2K3/IIS6.0), do we still need this patch? 2) Does it specifically solve only this error: The underlying connection was closed. An unexpected error
0
249
by: Tim Zych | last post by:
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...
8
9628
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query work from
8
2553
by: Merk | last post by:
I'm looking for a safe and maintainable way to store connection string info (connecting to SQL Server 2005 from .NET 2.0 Windows Forms client app); things like server name or IP address and database name. I need to provide the client application with this info for connecting to both a test SQL Server and a production server. I would prefer to NOT hard-code this info into the client application, and App.Config seems rather unsafe as the...
20
3269
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I get an error ? MSDN says the request is queued, but will I get an error in the open method ? ...
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7304
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.