我有2天的困難時間,並且無法弄清楚我應該如何處理我的實施。我不確定這是否真的可行。請幫助我。如何使用SqlConnection(ADO.Net)連接到ADO記錄集?
下面是我的情景:
我有一個NET的DLL其具有打開它後返回一個SqlConnection對象的方法。下面是(到我使用類似 - 這是一個樣本函數)的功能,我使用私鑰安裝此.dll在GAC
SqlConnection conn = new SqlConnection(); conn.ConnectionString = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myDatabase;Data Source=.\SQLEXPRESS;Trusted_Connection=true"; conn.Open();
。
- 然後註冊它使用regasm.exe實用程序,它將其導出爲tlb。
- 最後,我可以從我的ASP應用程序訪問這個.net dll,並且能夠從我使用.dll類對象訪問的方法獲取返回值。 (從方法訪問字符串值肯定沒有問題,但這種方法我試圖訪問SqlConnection ado.net對象)
下面是我的示例ASP頁面,顯示我如何訪問和使用連接對象:
<!-- #include file="adovbs.inc" -->
<%
set objdll = Nothing
set objConn = Nothing
//creating class object from the .net dll
set objdll = Server.CreateObject("gacDemo.clsGacDemo")
//accessing the GetConnection() method using the object.
//GetConnection() returns the SQLConnection ado.net object
objConn = objdll.GetConnection()
set objRS = Server.CreateObject("ADODB.Recordset")
objRs.Source = "SELECT COUNT(*) AS CityCount FROM city"
objRS.Open "select count(*) as count from city", objConn, 3, 3, 1
Count = objRS.Fields("count").value
response.Write Count
%>
我得到它我試圖修復它這個壞的錯誤,
錯誤類型: ADODB.Recordset(0x800A0BB9) 參數的錯誤類型,超出可接受的範圍,或與一個a相沖突諾特爾。
我不確定我是否可以在asp頁面中使用SqlConnection ado.net對象。
「flopdix」 - 這是一個巨魔嗎? – 2010-02-28 05:55:45
@Mitch更可能只是一個品味和禮貌令人難以置信的人。 – 2010-02-28 06:24:54
我不認爲你可以使用ADO.Net連接打開ADO記錄集。你是否有理由將「舊」與「新」混合?換句話說,爲什麼你不使用ADO連接,因爲你使用的是標準的ASP? – 2010-02-28 06:33:52