Re: Application role on connection
From: Dan Guzman (danguzman@nospam-earthlink.net)
Date: 02/25/03
- Next message: Mark Allison: "Re: Want to hide my ip"
- Previous message: Tibor Karaszi: "Re: Wiping MS SQL records"
- In reply to: Happygirl: "Re: Application role on connection"
- Next in thread: happygirl: "Re: Application role on connection"
- Reply: happygirl: "Re: Application role on connection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Dan Guzman" <danguzman@nospam-earthlink.net> Date: Tue, 25 Feb 2003 08:02:21 -0600
Happygirl, as I mentioned in my previous response, SQL Server can
execute only one SQL statement on a connection at a time. Because you
haven't read the recordset from the first query, ADO acquires a separate
SQL Server connection for the second query. The application role hasn't
been activated on that connection so you get the permissions error.
A simple technique to address your issue is to specify CursorLocation
adUseClient (instead of the default adUserServer) so that ADO will
immediately return the query results to your application. This will
free the connection (with the activated application role) for reuse.
Also, you might consider using OLE DB instead of ODBC. This allows you
to turn off connection pooling via the connection string so that it
doesn't interfere with your application role security. The example
below uses OLE DB with connection pooling disabled and client-side
cursors.
Set Conn = New Adodb.Connection
'OLE DB connection with connection pooling disabled
Conn.ConnectionString = "Provider=SQLOLEDB.1" & _
";Data Source=" & gsSQL70Server & _
";User ID=" & gsSQL70UID & _
";Password=" & Decrypt(gsSQL70PWD) & _
";Initial Catalog=" & gsSQL70DATABASE & _
";OLE DB Services=-2"
Conn.Open
'immediate retreive query results to the client
Conn.CursorLocation = adUseClient
Conn.Execute "sp_setapprole 'xxAppRole', 'xxAppRole'"
Dim strSQL As String
Dim Rst As Adodb.Recordset
Dim strSQL1 As String
Dim Rst1 As Adodb.Recordset
strSQL = "SELECT * from Test"
Set Rst = Conn.Execute(strSQL)
StrSQL1 = "SELECT * from Test";
Set Rst1 = Conn.Execute(strSQL1)
-- Hope this helps. Dan Guzman SQL Server MVP "Happygirl" <happygirl5354@hotmail.com> wrote in message news:0b1d01c2dc8d$2a488390$a401280a@phx.gbl... > The following are my sample code, i can successfully > execute strsql, but not strsql1, but however if i add one > more line in between "strsql.close", then both statement > can execute successfully, but since the program create > many of this recordset, should you provide any proper and > simple ways.. Thanks. > > Set Conn = New Adodb.Connection > Conn.ConnectionString = "Driver={SQL Server};SERVER=" > & gsSQL70Server & ";UID=" & gsSQL70UID & ";PWD=" & > Decrypt(gsSQL70PWD) & "" & ";DATABASE=" & gsSQL70DATABASE > Conn.Open > Conn.Execute "sp_setapprole 'xxAppRole', 'xxAppRole'" > > Dim strSQL As String > Dim Rst As Adodb.Recordset > Dim strSQL1 As String > Dim Rst1 As Adodb.Recordset > > strSQL = "SELECT * from Test" > Set Rst = Conn.Execute(strSQL) > > StrSQL1 = "SELECT * from Test"; > Set Rst1 = Conn.Execute(strSQL1) > >
- Next message: Mark Allison: "Re: Want to hide my ip"
- Previous message: Tibor Karaszi: "Re: Wiping MS SQL records"
- In reply to: Happygirl: "Re: Application role on connection"
- Next in thread: happygirl: "Re: Application role on connection"
- Reply: happygirl: "Re: Application role on connection"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|