---
title: "Undantagsfel med Class"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/87453-undantagsfel-med-class"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "LR^evil.sid"
published: "2003-10-02T08:31:27.000Z"
updated: "2003-10-02T09:20:29.000Z"
replies: 2
views: 226
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/87453-undantagsfel-med-class"
---

# Undantagsfel med Class

## #1 — LR^evil.sid, 2003-10-02T08:31Z

Nu har jag börjat prova mig fram med classer : )

Jag följde Vides exempel på webeye.nu och började modifiera så smått. Men jag får felmeddelanden typ varannan gång jag uppdaterar sidan. Vad kan det vara för fel?

clsSetCon.asp

```
<%
	Class SetCon
		Dim GetStrCon
		Dim GetStrSQL
		Dim ODB

		Public Property Let LetConnection(ConString)
			GetStrCon = ConString
		End Property
		Public Property Get GetConnection()
			GetConnection = GetStrCon
		End Property

		Public Property Let LetSQL(SQLString)
			GetStrSQL = SQLString
		End Property
		Public Property Get GetSQL()
			GetSQL = GetStrSQL
		End Property

		Public Sub InitConnection()
			Set ODB = Server.CreateObject("ADODB.Connection")
			ODB.Open(GetConnection)
		End Sub

		Public Sub FinalizeConnection()
			ODB.Close
			Set ODB = Nothing
		End Sub

		Private Function GetDataBase()
			Set GetDataBase = ODB
		End Function

		Public Function GetDbData()
			Dim ORS
[b]line « 37 »[/b]	[red]Set ORS = GetDataBase.Execute(GetSQL)[/red]

			If Not ORS.EOF Then
				GetDbData = ORS.Fields("usr")
			End If
		End Function
	End Class
%>
```

test.asp

```
<%
	Option Explicit
	Dim cSetCon
	Response.Buffer = True

	Set cSetCon = New SetCon
	With cSetCon
		.LetConnection = "Driver={MySql};server=localhost;database=;uid=;pwd=;option=16387;"
		.LetSQL = "select * from members"
		.InitConnection()
		Response.Write .GetDbData() & "<br>"
		.FinalizeConnection()
	End With
	Set cSetCon = Nothing
%>
<!-- #Include Virtual = '/suck/classes/clsSetCon.asp' -->
```

Felmeddelande:

```
Körningsfel i Microsoft VBScript ( 0x800A01FB ) 
Ett undantag uppstod: 'GetDataBase.Execute' 	
file: /suck/classes/clsSetCon.asp
line: « 37 »
```

Permalänk: https://www.webforum.nu/p/87453

## #2 — Vide, 2003-10-02T09:14Z

Borde inte den raden se ut såhär:
Set ORS = ODB.Execute(GetSQL)

\[R\]Vänta nu, jag är ju ute och cyklar, men vad händer om du gör som min kod? Fungerar det då?

Permalänk: https://www.webforum.nu/p/1173303

## #3 — LR^evil.sid, 2003-10-02T09:20Z

U tell me...

```
'Funktion för att återge connectionobjektet.
  'Notera att den är private, och kan bara anropas ifrån klassen.
[b]  private function getDb()
    set getDb = oDb
  end function[/b]

  'Funktion för att återge det användarnamn som har id = intCurrentUserId.
  public function getUserName()
    dim strSQL
    dim oRs

    strSQL = "select UserName from tblUsers where UserId = " & intCurrentUserId
    set oRs = [b]getDb[/b].execute( strSQL )
```

Men det spelar ingen roll ändå. Får samma felmeddelande:

```
Ett undantag uppstod: 'ODB.Execute'
```

\[R1\]öumm... bara kopiera den rakt av?

\[R2\]Hmm... alla sidor på min server ger fel typ varannan gång. Alla som använder sig av .execute iaf. Vad tror ni är fel då?

Kanske starta om IIS? Räcker sådant?

Permalänk: https://www.webforum.nu/p/1173305

---

Tråden på webben: https://www.webforum.nu/amne/asp/87453-undantagsfel-med-class
