The following error happens in my ASP.NET page from time to time. It will disappear after I restart the SQL Server. I guess I messed up in the garbage collection, but I really don't know what to do except using "conn=nothing" statement, can anyone help me with this?
Thanks!
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
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.Runtime.InteropServices.COMException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Source Error:
Line 39: Public Sub New()Line 40: conn = New ADODB.ConnectionLine 41: conn.Open("Provider=SQLOLEDB.1;Persist Security Info=xxxxx;User ID=xxxxx;Initial Catalog=xxxx;Data Source=xxx")Line 42: rs = New ADODB.RecordsetLine 43: my_UserID = 0
DWesthead:
try encasing your db interaction in a using{} block - that way it will make sure that the dispose() method has been called and the objects marked for garbage collection.
I am not using C#, I am using VB, do you know the garbage collection using VB?
Thanks!
|||In VB you can use something like this:
Using connectionAsNew SqlConnection()
connection.ConnectionString = connectionString
connection.Open()
Console.WriteLine("State: {0}", connection.State)
Console.WriteLine("ConnectionString: {0}", _
connection.ConnectionString)
End Using
I tried to do that, but the "Using" tag is not recognized, maybe there is no such a thing as "USING" in VB?
|||Using works for me:
Using connAsNew SqlConnectionEndUsingUsing turns blue, and when I finish the first line, it inserts the End using statement for me.
Curious, why are you using adodb instead of sqlconnect/sqlcommand?
|||I am using adodb because I am used to it. I programed several ASP program using adodb.
I think I might not have to most recent asp.net sdk install then, I will try to install it now.
Could you tell me any different from sqlconnection and the adodb connection? how to use sqlconnection?
Thanks!
Alex
|||They are very similiar. The easiest way to make a correct sqlconnection string is to drop a sqldatasource control on your page, then use the wizard
I often do that even for connection strings that I use programmatically, I just tell the wizard to put it in web.config, and after the wizard is done, I'll delete the sqldatasource from the page, and access the connectionstring programmatically.
No comments:
Post a Comment