Showing posts with label sqlserver. Show all posts
Showing posts with label sqlserver. Show all posts

Thursday, March 22, 2012

Calling parameterised views from VB

I'd really appreciate your help creating a parameterised view in SQL
Server, which I can then invoke from VB5. I'm using DAO and ODBC to
connect to SQL Server 2000.

I can open Tables and Views, but can't find how to create or use a
"query" parameter. If I use the "?" (in the SQL Enterprise manager
View design mode), the syntax checker verifies the query ok, but I
then get the message "Parameters cannot be used in this query type".
It doesn't like the %var% terminology at all here.

I am sure I could build the full query in VB and save it to the Server
"on-the-fly", but this partly defeats the object, doesn't it?

I could really do with a couple of pointers: (a) how to define the
view/query in Ent Manager and (b) how to invoke it from VB, supplying
the parameter.

Thanks ever so in anticipation.

PhilPhil Sowden (philsowden@.dataservicesltd.co.uk) writes:
> I'd really appreciate your help creating a parameterised view in SQL
> Server, which I can then invoke from VB5. I'm using DAO and ODBC to
> connect to SQL Server 2000.
> I can open Tables and Views, but can't find how to create or use a
> "query" parameter. If I use the "?" (in the SQL Enterprise manager
> View design mode), the syntax checker verifies the query ok, but I
> then get the message "Parameters cannot be used in this query type".
> It doesn't like the %var% terminology at all here.
> I am sure I could build the full query in VB and save it to the Server
> "on-the-fly", but this partly defeats the object, doesn't it?
> I could really do with a couple of pointers: (a) how to define the
> view/query in Ent Manager and (b) how to invoke it from VB, supplying
> the parameter.

Views cannot be parameterized in SQL Server. However there are table-valued
functions, which are about the same thing. Example:

CREATE FUNCTION myorders (@.custid nchar(5)) RETURNS TABLE AS
RETURN (SELECT * FROM Northwind..Orders WHERE CustomerID = @.custid)
go
SELECT * FROM myorders(N'ALFKI')

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks very much indeed for your help, Erland.

I had tried this, amongst many other things. However, I didn't realise
I'd got it right, as I couldn't work out how to populate a VB recordset
object from an SQL function.

I normally (in Access) open a database object, then use something like:

lsSQL = "Select * from Northwind.Orders WHERE CustomerID = " &
llCustID
Set lrsOrders = gdbMain.OpenRecordset(lsSQL)
lrsOrders.MoveFirst

where:
gdbMain is a globally-defined database object
lrsOrders is a locally-defined recordset object

This second part of my question probably belongs in the VB or Access
newsgroups, I'm sure, but maybe you can help again, Erland?

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Phil (philsowden@.nospam.dataservicesltd.co.uk) writes:
> I had tried this, amongst many other things. However, I didn't realise
> I'd got it right, as I couldn't work out how to populate a VB recordset
> object from an SQL function.
> I normally (in Access) open a database object, then use something like:
> lsSQL = "Select * from Northwind.Orders WHERE CustomerID = " &
> llCustID
> Set lrsOrders = gdbMain.OpenRecordset(lsSQL)
> lrsOrders.MoveFirst
> where:
> gdbMain is a globally-defined database object
> lrsOrders is a locally-defined recordset object

So to call the table function you would say:

lsSQL = "Select * from myorders(" & llCustID & ")"

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||That's brilliant, thanks, Erland. I've applied that example to my
system and got it to work fine within SQL Server now.

However, when I try:
lsSQL = "Select * from FindCust('07940437220')"
Set lrsTemp = gdbSparc.OpenRecordset(lsSQL)

...in VB, I get "Error 3131 - Syntax Error in FROM clause". It's as if
VB doesn't recognise the function exists at all?

The identical code works fine (as a View) within SQL Server (n.b. the
customer reference I'm using is a 14 character nvarchar field).

I'm sorry to be such a novice! I also realise that this may not be the
correct forum - but it may be that you are able to help.

Thanks once again,

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Phil (philsowden@.nospam.dataservicesltd.co.uk) writes:
> That's brilliant, thanks, Erland. I've applied that example to my
> system and got it to work fine within SQL Server now.
> However, when I try:
> lsSQL = "Select * from FindCust('07940437220')"
> Set lrsTemp = gdbSparc.OpenRecordset(lsSQL)
> ..in VB, I get "Error 3131 - Syntax Error in FROM clause". It's as if
> VB doesn't recognise the function exists at all?

That right. In fact VB does not know anything about SQL at all. I don't
know what this OpenRecordset is, but that much I can tell that the
error message you get does not come from SQL Server. And since VB
does not SQL, it must be someother data source you are querying. Didn't
you mention Access? Well, I don't know anything about Access, so...

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Cool. Thanks again for your help, Erland, I'm sure I'll resolve it
shortly.

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||In article <403a0e0e$0$198$75868355@.news.frii.net>, Phil <philsowden@.nospam.dataservicesltd.co.uk> wrote:
>That's brilliant, thanks, Erland. I've applied that example to my
>system and got it to work fine within SQL Server now.
>However, when I try:
>lsSQL = "Select * from FindCust('07940437220')"
>Set lrsTemp = gdbSparc.OpenRecordset(lsSQL)
>...in VB, I get "Error 3131 - Syntax Error in FROM clause". It's as if
>VB doesn't recognise the function exists at all?
>The identical code works fine (as a View) within SQL Server (n.b. the
>customer reference I'm using is a 14 character nvarchar field).
>I'm sorry to be such a novice! I also realise that this may not be the
>correct forum - but it may be that you are able to help.
>Thanks once again,
>Phil
>*** Sent via Developersdex http://www.developersdex.com ***
>Don't just participate in USENET...get rewarded for it!

You have a table named FindCust('07940437220') in your database? Who came
up with an impossible to remember name like that?|||Rico,

Thanks for your interest.

If you're able to tell me how to design a parameterised SQL View and
call it from VB, I'd be ecstatic! I'm sure I can fix that function name
quite easily!

The SQL table is called "Cust", but I had to create a table-type
function to return a view / query of selected records with a parameter.
The "FindCust()" function returns a recordset of customers found for the
parameter value given. I thought the name was quite meaningful,
actually!

The call you're looking at is my failed attempt to call that same
function from within VB (version 5, using DAO with ODBC connection to
SQL Server).

Ideas most welcome...!

Phil

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Phil (philsowden@.nospam.dataservicesltd.co.uk) writes:
> The call you're looking at is my failed attempt to call that same
> function from within VB (version 5, using DAO with ODBC connection to
> SQL Server).

Aha, so that OpenRowset is DAO? Now, I don't know DAO, and it might be
that DAO is itself trying interpreting the SQL statement. In such case
you are probably out of luck, because DAO is too old to know about
table-value functions added to SQL2000. I would guess that DAO is not
equipped to handle that. But if it's ODBC which performs the syntax
check, then it's only a matter of getting version 2.6 or later of the
MDAC. They are available at:
http://www.microsoft.com/downloads/...&DisplayLang=en

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Calling Oracle Stored Proc from SqlServer

I am trying to call an Oracle stored procedure from SqlServer. I have tried
both the MS and Oracle OLE DB Providers.
I can select records from Oracle and I can insert records to Oracle. The
stored proc call dies.
The interesting part in this is that I can write a VB script that calls the
stored procedure from the server that the SqlServer instance is running on
and it is able to execute the proc. The VB script uses Oracle's OLE DB
Provider.
We are using SqlServer 2000 and Oracle 9.2.0.6
I am sure that there is something setup incorrectly with SqlServer.
Any ideas
RSLHimm?
So i think u must use sp_OACreate, sp_OAMethod, sp_OADestroy methods in sql
server procedures or triggers.
First, make a dll for oracle actions. And call dll in sql server t-sql with
those method.
Message posted via http://www.droptable.comsql

Calling Oracle Stored Proc from SqlServer

I am trying to call an Oracle stored procedure from SqlServer. I have tried
both the MS and Oracle OLE DB Providers.
I can select records from Oracle and I can insert records to Oracle. The
stored proc call dies.
The interesting part in this is that I can write a VB script that calls the
stored procedure from the server that the SqlServer instance is running on
and it is able to execute the proc. The VB script uses Oracle's OLE DB
Provider.
We are using SqlServer 2000 and Oracle 9.2.0.6
I am sure that there is something setup incorrectly with SqlServer.
Any ideas
RSLHimm?
So i think u must use sp_OACreate, sp_OAMethod, sp_OADestroy methods in sql
server procedures or triggers.
First, make a dll for oracle actions. And call dll in sql server t-sql with
those method.
--
Message posted via http://www.sqlmonster.com

Calling Oracle Stored Proc from SqlServer

I am trying to call an Oracle stored procedure from SqlServer. I have tried
both the MS and Oracle OLE DB Providers.
I can select records from Oracle and I can insert records to Oracle. The
stored proc call dies.
The interesting part in this is that I can write a VB script that calls the
stored procedure from the server that the SqlServer instance is running on
and it is able to execute the proc. The VB script uses Oracle's OLE DB
Provider.
We are using SqlServer 2000 and Oracle 9.2.0.6
I am sure that there is something setup incorrectly with SqlServer.
Any ideas
RSL
Himm?
So i think u must use sp_OACreate, sp_OAMethod, sp_OADestroy methods in sql
server procedures or triggers.
First, make a dll for oracle actions. And call dll in sql server t-sql with
those method.
Message posted via http://www.droptable.com

Thursday, March 8, 2012

Callable statements, SQLServer and JRun

Hi,

I'm developing a java application which uses SQL Server as the
database. I use Callable Statements to connect to the database. I use
JRun as the app server. When
running the application I want to be able to monitor locks/process
info etc in the 'Current Activity' section in the 'Management'
section
in SQL Server.

The problem is that at the moment if I look at the 'Last TSQL command
batch' in the process or lock, it does not display the sql for the
current call. It displays what seems to be the precompiled call:
#jdbc#9;1

Anyone know how to get it to display the sql?

Is it a driver issue or is there a SQL Server setting to get it to do
this?

Thanks(cormac.foley@.gmail.com) writes:

Quote:

Originally Posted by

I'm developing a java application which uses SQL Server as the
database. I use Callable Statements to connect to the database. I use
JRun as the app server. When
running the application I want to be able to monitor locks/process
info etc in the 'Current Activity' section in the 'Management'
section
in SQL Server.
>
>
The problem is that at the moment if I look at the 'Last TSQL command
batch' in the process or lock, it does not display the sql for the
current call. It displays what seems to be the precompiled call:
#jdbc#9;1
>
>
Anyone know how to get it to display the sql?
>
>
Is it a driver issue or is there a SQL Server setting to get it to do
this?


Didn't you ask the same question a week ago or two? Yes, that was
another newsgroup, but at least you should have learnt by now that it
is a driver issue. And I hope that you should know that you should
use parameterised statements.

Well, I see on Google Groups that you also have posted your
question to comp.lang.java.programmer. Too that you did not cross-post.
It would have been interesting to see the answers from the Java folks.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||On Feb 12, 10:29 pm, Erland Sommarskog <esq...@.sommarskog.sewrote:

Quote:

Originally Posted by

(cormac.fo...@.gmail.com) writes:

Quote:

Originally Posted by

I'm developing a java application which uses SQL Server as the
database. I use Callable Statements to connect to the database. I use
JRun as the app server. When
running the application I want to be able to monitor locks/process
info etc in the 'Current Activity' section in the 'Management'
section
in SQL Server.


>

Quote:

Originally Posted by

The problem is that at the moment if I look at the 'Last TSQL command
batch' in the process or lock, it does not display the sql for the
current call. It displays what seems to be the precompiled call:
#jdbc#9;1


>

Quote:

Originally Posted by

Anyone know how to get it to display the sql?


>

Quote:

Originally Posted by

Is it a driver issue or is there a SQL Server setting to get it to do
this?


>
Didn't you ask the same question a week ago or two? Yes, that was
another newsgroup, but at least you should have learnt by now that it
is a driver issue. And I hope that you should know that you should
use parameterised statements.
>
Well, I see on Google Groups that you also have posted your
question to comp.lang.java.programmer. Too that you did not cross-post.
It would have been interesting to see the answers from the Java folks.
>
--
Erland Sommarskog, SQL Server MVP, esq...@.sommarskog.se
>
Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx- Hide quoted text -
>
- Show quoted text -


He he..u the newsgroup police or something? Yes I asked the same
question last week on Yahoo. Am interested in getting numerous
opinions on this.

I have tried a number of different types of driver and all of them
still result in the compiled sql in the 'Last TSQL command batch'
value. Interestingly when I use Microsoft drivers they seem to compile
everything..and Macromedia drivers just seem to compile stored
procedure calls which have parameters.

I need to use stored procedures/CallableStatements - it may be that is
not possible to have the uncompiled sql available in the log when
using CallableStatements no matter what driver I use.