Thursday, March 29, 2012
Distributed Query Connection Issues
on ServerB. My client app connects to ServerA and uses a stored procedure to
retrieve a dataset from both ServerA and ServerB.
While developing the app (using SQL 2K Dev on my workstation), I used a
linked server approach. I linked ServerB and refered to the database as
ServerB.DBName.dbo.TableName and it worked fine.
I'd like to use trusted connections and my users will have SQL server access
to both servers.
Here is the problem:
If I install the app on another workstation (i.e. not on the one running
ServerA), the I get:
Msg 18452
Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Using Query Analyser from the third workstation I can connect to both
serverA and ServerB using Windows Authentication, with both Named Pipes and
TCP/IP protocols.
What am I doing wrong?
Thank you very much for your help.
The issue you are hitting is sometimes called a double hop.
You are wanting to pass Windows credentials from one server
to another. The following KB article explains the issue and
still applies to SQL Server 2000 if you don't have kerberos
enabled and account delegation setup. The article specifies
SQL 7 as you can't get around this on SQL 7 and have to use
other methods to not hit issues with double hops.
PRB: Message 18456 from a Distributed Query
http://support.microsoft.com/?id=238477
Under SQL Server 2000, If you want to use Windows
authentication in this scenario, you need to use Active
Directory, enable kerberos and setup account delegation.
You can find more information in SQL Server books online
under the topic Security Account Delegation
-Sue
On Mon, 10 Jan 2005 10:55:01 -0800, "Konstantin"
<Konstantin@.discussions.microsoft.com> wrote:
>I have the following situation: I have a database on ServerA and a database
>on ServerB. My client app connects to ServerA and uses a stored procedure to
>retrieve a dataset from both ServerA and ServerB.
>While developing the app (using SQL 2K Dev on my workstation), I used a
>linked server approach. I linked ServerB and refered to the database as
>ServerB.DBName.dbo.TableName and it worked fine.
>I'd like to use trusted connections and my users will have SQL server access
>to both servers.
>Here is the problem:
>If I install the app on another workstation (i.e. not on the one running
>ServerA), the I get:
>Msg 18452
>Login failed for user '(null)'. Reason: Not associated with a trusted SQL
>Server connection.
>Using Query Analyser from the third workstation I can connect to both
>serverA and ServerB using Windows Authentication, with both Named Pipes and
>TCP/IP protocols.
>What am I doing wrong?
>Thank you very much for your help.
Distributed Query Connection Issues
on ServerB. My client app connects to ServerA and uses a stored procedure to
retrieve a dataset from both ServerA and ServerB.
While developing the app (using SQL 2K Dev on my workstation), I used a
linked server approach. I linked ServerB and refered to the database as
ServerB.DBName.dbo.TableName and it worked fine.
I'd like to use trusted connections and my users will have SQL server access
to both servers.
Here is the problem:
If I install the app on another workstation (i.e. not on the one running
ServerA), the I get:
Msg 18452
Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Using Query Analyser from the third workstation I can connect to both
serverA and ServerB using Windows Authentication, with both Named Pipes and
TCP/IP protocols.
What am I doing wrong?
Thank you very much for your help.The issue you are hitting is sometimes called a double hop.
You are wanting to pass Windows credentials from one server
to another. The following KB article explains the issue and
still applies to SQL Server 2000 if you don't have kerberos
enabled and account delegation setup. The article specifies
SQL 7 as you can't get around this on SQL 7 and have to use
other methods to not hit issues with double hops.
PRB: Message 18456 from a Distributed Query
http://support.microsoft.com/?id=238477
Under SQL Server 2000, If you want to use Windows
authentication in this scenario, you need to use Active
Directory, enable kerberos and setup account delegation.
You can find more information in SQL Server books online
under the topic Security Account Delegation
-Sue
On Mon, 10 Jan 2005 10:55:01 -0800, "Konstantin"
<Konstantin@.discussions.microsoft.com> wrote:
>I have the following situation: I have a database on ServerA and a database
>on ServerB. My client app connects to ServerA and uses a stored procedure t
o
>retrieve a dataset from both ServerA and ServerB.
>While developing the app (using SQL 2K Dev on my workstation), I used a
>linked server approach. I linked ServerB and refered to the database as
>ServerB.DBName.dbo.TableName and it worked fine.
>I'd like to use trusted connections and my users will have SQL server acces
s
>to both servers.
>Here is the problem:
>If I install the app on another workstation (i.e. not on the one running
>ServerA), the I get:
>Msg 18452
>Login failed for user '(null)'. Reason: Not associated with a trusted SQL
>Server connection.
>Using Query Analyser from the third workstation I can connect to both
>serverA and ServerB using Windows Authentication, with both Named Pipes and
>TCP/IP protocols.
>What am I doing wrong?
>Thank you very much for your help.
distributed partitioned view + procedure
Create view Viewall
as
select * from server1.db.dbo.abc
union all
select * from server2.db.dbo.abc
union all
select * from server3.db.dbo.abc
union all
select * from server4.db.dbo.abc
And if one server say server 2 is unavailable, will the view fail to run ?
If so , how can i still let the stored proc run
and same for a stored procedure
Create proc Viewall
as
select * from server1.db.dbo.abc
union all
select * from server2.db.dbo.abc
union all
select * from server3.db.dbo.abc
union all
select * from server4.db.dbo.abc
What happens in this case if server2 is unavailable ? And also a way to let
it run should any server be made unavailable> And if one server say server 2 is unavailable, will the view fail to run ?
For a query where the optimizer realizes it has to hit server 2 will fail.
> If so , how can i still let the stored proc run
Have redundancy on the servers.
Same goes for stored procedures.
--
Tibor Karaszi, SQL Server MVP
Archive at: http://groups.google.com/groups?oi=djq&as ugroup=microsoft.public.sqlserver
"Hassan" <fatima_ja@.hotmail.com> wrote in message news:OHe5POhkDHA.1284@.TK2MSFTNGP09.phx.gbl...
> If i have a view such as
> Create view Viewall
> as
> select * from server1.db.dbo.abc
> union all
> select * from server2.db.dbo.abc
> union all
> select * from server3.db.dbo.abc
> union all
> select * from server4.db.dbo.abc
>
> And if one server say server 2 is unavailable, will the view fail to run ?
> If so , how can i still let the stored proc run
> and same for a stored procedure
> Create proc Viewall
> as
> select * from server1.db.dbo.abc
> union all
> select * from server2.db.dbo.abc
> union all
> select * from server3.db.dbo.abc
> union all
> select * from server4.db.dbo.abc
> What happens in this case if server2 is unavailable ? And also a way to let
> it run should any server be made unavailable
>
>
Distributed APP strategies-What to do where is killing me...
"It's generally better to use the stored procedure option to perform the
transaction against the database rather than initiate a transaction on a
Connection object. When possible, you should isolate transactions to the
data tier, because it's the DBMS that actually performs the transactions."
OK, that seems reasonbale to me. Also, it makes sense to me that Business
Rule edits should be performed in the Application tier.
Howver, what if the Business edit requires a DB lookup, should it be
performed in the database in a SP or in a Buiness Object on the app tier?
I expect the "correct" answer is in the App Tier? Hower, if the edit is
performed in the App tier and if it passes the edit, and a SP is called to
perform the update, it seems to me that unless we have placed the Business
Rule lookup AND the UPDATE in a TRANSACTION by intiatiating a Transaction on
the Connection object, that we cannot guarantee that at the time of the db
update, that the Business Rule edit check would still pass. Some other user
may have snuck in a performed an update in between the Business Rule check
on the application Tier and the actual update to the database!
I guess I need to understand more about LOCKING. If the records queried by
the Business Edit were still locked at the time of the update, we could
assume that the state of the database is still such that an update is still
permitted. I assumed that enclosing the Business edit and the update in a
transaction would ensure that.
Now my head starts hurting when I throw into the mix the fact that we are
using .NET Remoting (Well Known Single Call) STATELESS objects.
I understand that STATELESS remote objects allow for increase scalability
and load balancing, and so that is why this approach was probably taken.
Hwoever, since the objects ae stateless, each time we instantiate an object
to perform a database call, we are establishing a new connection. And this
presents the problem of how do you tie the Business Edit lookup and the Data
Update into a single transaction by initiating a Transaction on the
Connection object is a new Connection is established with each call to the
database!
Furthermore, if you have two business abojects, Account and User, and you
want to call the ACCOUNT.AddNewAccount method and the User.AddNewUser method
and have both operation performed in a transaction, how do you do this if a
each object is establishing its own connection!?
The answer, it seems to me, is that you can't, that you need to create a new
object to do both, but this throws away the ability to reuse existing
objects.
It seems that the more granular an Object is the more reusable it is, but by
using SingleCall Remoting we do not have the ability to tie multiple updates
into a transaction. Not to mention that the Account object need to perform
an BO edit before adding an Account (to make sure it doesnt already exist in
the db) and the User object needs to peform an edit before adding a user,
that this will require *TWO* round trips to the server, which hurts
performance. By writing a new object to do both at the same time, you
increase performance by making one trip by throw away reusability since most
of the time you will need to do one operation or the otehr, not both.
I could go on and on. I hope you were able to follw the jist it.
I wish you MVPs were sitting next to my cube.
Many thanks for all the help you've given me in just a short time..
Chad
"Chad" wrote:
> I just read this quote at DevX.Com
> "It's generally better to use the stored procedure option to perform the
> transaction against the database rather than initiate a transaction on a
> Connection object. When possible, you should isolate transactions to the
> data tier, because it's the DBMS that actually performs the transactions."
> OK, that seems reasonbale to me. Also, it makes sense to me that Business
> Rule edits should be performed in the Application tier.
> Howver, what if the Business edit requires a DB lookup, should it be
> performed in the database in a SP or in a Buiness Object on the app tier?
>
Thats where you need to the data to apply your rules, you're right..
> I expect the "correct" answer is in the App Tier? Hower, if the edit is
> performed in the App tier and if it passes the edit, and a SP is called to
> perform the update, it seems to me that unless we have placed the Business
> Rule lookup AND the UPDATE in a TRANSACTION by intiatiating a Transaction
on
> the Connection object, that we cannot guarantee that at the time of the db
> update, that the Business Rule edit check would still pass. Some other use
r
> may have snuck in a performed an update in between the Business Rule check
> on the application Tier and the actual update to the database!
This is a concurrency issue, I create a BINARY_CHECKSUM containing the rows
that will be updated when the data is loaded into the business object, it's
a
private readonly property, this gets passed back to the procedure that
updates if the checksum is different at the time of update then you know tha
t
the data has changed since the read, do whatever to handle it then.
> I guess I need to understand more about LOCKING. If the records queried by
> the Business Edit were still locked at the time of the update, we could
> assume that the state of the database is still such that an update is stil
l
> permitted. I assumed that enclosing the Business edit and the update in a
> transaction would ensure that.
The locking will only occur when you do the update.
> Now my head starts hurting when I throw into the mix the fact that we are
> using .NET Remoting (Well Known Single Call) STATELESS objects.
>
Don't let this confuse you these are totaly seperate techonologies, have you
looked at CSLA...? It's a very well thought out object oriented framework of
which there are many users...
http://groups.msn.com/CSLANET
http://www.apress.com/book/bookDisplay.html?bID=198
Also take a look at Ingo Rammers remoting book, very good stuff must have if
your doing .Net remoting.
http://www.apress.com/book/bookDisplay.html?bID=108
> I understand that STATELESS remote objects allow for increase scalability
> and load balancing, and so that is why this approach was probably taken.
> Hwoever, since the objects ae stateless, each time we instantiate an objec
t
> to perform a database call, we are establishing a new connection. And this
> presents the problem of how do you tie the Business Edit lookup and the Da
ta
> Update into a single transaction by initiating a Transaction on the
> Connection object is a new Connection is established with each call to the
> database!
> Furthermore, if you have two business abojects, Account and User, and you
> want to call the ACCOUNT.AddNewAccount method and the User.AddNewUser meth
od
> and have both operation performed in a transaction, how do you do this if
a
> each object is establishing its own connection!?
> The answer, it seems to me, is that you can't, that you need to create a n
ew
> object to do both, but this throws away the ability to reuse existing
> objects.
In these cases where you have more than one business object that you want to
enlist in the same transaction you might create a controller class that
orchestrates the transaction using the EnterpriseServices.ServicedComponent
functionality which is basically MTS for .Net. This is not an ADO.NET
transaction anymore, even though your still using an ADO transaction in your
business object and maybe even T-SQL transactions in your sp's. Nonetheless
they'll be controlled by the serviced component, keep in mind this creates a
LOT of overhead, don't do this unless you have to.
> It seems that the more granular an Object is the more reusable it is, but
by
> using SingleCall Remoting we do not have the ability to tie multiple updat
es
> into a transaction. Not to mention that the Account object need to perform
> an BO edit before adding an Account (to make sure it doesnt already exist
in
> the db) and the User object needs to peform an edit before adding a user,
> that this will require *TWO* round trips to the server, which hurts
> performance. By writing a new object to do both at the same time, you
> increase performance by making one trip by throw away reusability since mo
st
> of the time you will need to do one operation or the otehr, not both.
> I could go on and on. I hope you were able to follw the jist it.
> I wish you MVPs were sitting next to my cube.
> Many thanks for all the help you've given me in just a short time..
> Chad
>
>
Tuesday, March 27, 2012
Distincts databases on the same stored procedure
Hi!
I need to use two distincts databases on the same stored procedure. One, database1, is where I want to place the procedure, and where the table the procedure populates is (table1). The other, database2, hosts the table (table2) from where I select some data to put into table1 in database1.
Database1 name is fixed, while database2 name may change. So, I would like to pass database2 name as a parameter to the procedure. In this simple example, it works fine:
use database1
go
create procedure teste @.db_name varchar(10) as
exec ('select * from ' + @.db_name + '.dbo.table2')
But the problem is that in my procedure, database2 is used in a cursor, something like this:
create procedure myProcedure @.year int, @.pDatabase2 varchar(30) AS
declare ...
WHILE ...
BEGIN
...
declare cursor1 cursor for
select column1, column2 from @.pDatabase2.dbo.table2
where ...
open cursor1
fetch next from cursor1 into ...
close cursor1
deallocate cursor1
-- insert data into table
INSERT INTO table1
VALUES...
....
And I get an error if I try to use the exec! How can I do it? Can anyone help me please?
Thank you!
Try to rebuild your query; either refrain from using cursor, or from using variable for a database.
Also, you can EXEC('select column1, column2 from ' + @.pDatabase2 + '.dbo.table2 INTO ##TempTable'), then run a cursor over TempTable.
|||You can execute the declare cursor dynamically if you use a global cursor like:
set @.dbname = quotename(@.pDatabase2)
exec ('declare cursor1 cursor global for select column1, column2 from ' + @.dbname + '.dbo.table2')
open cursor1
...
But it seems like what you are doing is unnecessary and complicated. You should instead do the following which is easier to manage.
1. Create a stored procedure in database2 that returns the expected results from table2 like:
create procedure gettable2
as
select col1, col2 from table2
2. And now do insert..exec from database1 like:
set @.sp = quotename(@.pDatabase2) + '.sys.sp_executesql'
insert into table1
exec @.sp 'gettable2'
Alternatively, you can just use approach in step #2 and issue the SELECT directly like:
set @.sp = quotename(@.pDatabase2) + '.sys.sp_executesql'
insert into table1
exec @.sp 'select col1, col2 from table2'
The SP is approach is slightly better from a security standpoint since you don't have to give SELECT permission on the table(s). With either approach, you will have to watch out for ownership chaining issues for example. See Books Online for more details on how ownership chaining works and db ownership chaining option.
|||Thank you a lot, it's much easier now!
Sunday, March 25, 2012
DISTINCT MonthName for a lot of dates....
I have a table with several rows, each has a datetime field.
I want to query this table, ideally with my stored procedure and return just
a set of month names/numbers if possible, but I keep going around in circles
either getting ALL of my dates back with the names in a new column, or only
the month names, but order incorrectly...
table structure:
PregnancyLog
LogID int
LogDateTime datetime
sample data
LogID, LogDateTime
1,29/01/05
2,30/01/05
3,01/02/05
4,03/02/05
5,04/02/05
6,11/03/05
7,12/03/05
8,23/04/05
9,12/08/05
Expected results
MonthName, MonthNumber
January, 1
February, 2
March, 3
April, 4
August, 8
Any help would be appreciated - my only current resolution would be to
create a view of my data which gets me the month names, and then do a
distinct on that with the stored procedure, but I'd rather just do it once
in the stored procedure if possible.
Regards
Rob"Rob Meade" wrote ...
> Any help would be appreciated
I hate it when this happens...looks like I might have sussed it myself...
SELECT DATENAME(MONTH, LogDateTime) AS MonthName, MONTH(LogDateTime)
FROM PregnancyLog
GROUP BY DATENAME(MONTH, LogDateTime), MONTH(LogDateTime)
ORDER BY MONTH(LogDateTime)
Does that look acceptable to anyone? It gives me the results I wanted but I
just wanted to make sure..
Regards
Rob|||On Thu, 24 Nov 2005 23:20:43 GMT, Rob Meade wrote:
>"Rob Meade" wrote ...
>
>I hate it when this happens...looks like I might have sussed it myself...
>SELECT DATENAME(MONTH, LogDateTime) AS MonthName, MONTH(LogDateTime)
>FROM PregnancyLog
>GROUP BY DATENAME(MONTH, LogDateTime), MONTH(LogDateTime)
>ORDER BY MONTH(LogDateTime)
>Does that look acceptable to anyone? It gives me the results I wanted but
I
>just wanted to make sure..
>Regards
>Rob
>
Hi Rob,
Looks good.
Here's an (untested) alternative:
SELECT DISTINCT DATENAME(month, LogDateTime) AS MonthName,
MONTH(LogDateTime)
FROM PregnancyLog
ORDER BY MONTH(LogDateTime)
Maybe you can even remove the MONTH(LogDateTime) from the SELECT, but
I'm not sure of that.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||"Hugo Kornelis" wrote ...
> Looks good.
Thank you :o)
> Maybe you can even remove the MONTH(LogDateTime) from the SELECT, but
> I'm not sure of that.
Cheers for that Hugo, it worked a treat, I left the MONTH(LogDateTime) in,
and added an alias of MonthNumber as I use this in the application.
But its still less code than I had - many thanks :o)
Regards
Rob|||Hi Hugo,
Any ideas how I would add a "count" to the end of the result set of the
number of log items for each month returned by the existin query...
Ie...
MonthName MonthNumber Counter
January 1 2
February 2 6
March 3 15
Any help would be really appreciated, I've tried adding COUNT(LogID) to my
query, but then I get message telling me that things need adding to the
aggregate function or the group by clause, which I did try adding again but
then I have to lose the order by or else I get EVERY row
again...nightmare..
Any help appreciated.
Regards
Rob|||On Fri, 25 Nov 2005 23:17:45 GMT, Rob Meade wrote:
>Hi Hugo,
>Any ideas how I would add a "count" to the end of the result set of the
>number of log items for each month returned by the existin query...
>Ie...
>MonthName MonthNumber Counter
>January 1 2
>February 2 6
>March 3 15
>Any help would be really appreciated, I've tried adding COUNT(LogID) to my
>query, but then I get message telling me that things need adding to the
>aggregate function or the group by clause, which I did try adding again but
>then I have to lose the order by or else I get EVERY row
>again...nightmare..
>Any help appreciated.
>Regards
>Rob
>
Hi Rob,
If you need to add a count (or any other aggregate function), then you
can't use my shorter version; you'll have to return to your original
version with GROUP BY.
SELECT DATENAME(MONTH, LogDateTime) AS MonthName, MONTH(LogDateTime),
COUNT(LogID) AS Counter
FROM PregnancyLog
GROUP BY DATENAME(MONTH, LogDateTime), MONTH(LogDateTime)
ORDER BY MONTH(LogDateTime)
should work. If not, you'll need to provide more information, as
described in www.aspfaq.com/5006.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||"Hugo Kornelis" wrote ...
> SELECT DATENAME(MONTH, LogDateTime) AS MonthName, MONTH(LogDateTime),
> COUNT(LogID) AS Counter
> FROM PregnancyLog
> GROUP BY DATENAME(MONTH, LogDateTime), MONTH(LogDateTime)
> ORDER BY MONTH(LogDateTime)
> should work. If not, you'll need to provide more information, as
> described in www.aspfaq.com/5006.
Hi Hugo,
Worked a treat, many thanks - I thought I tried exactly that, but obviously
not, when I tried it, SQL moaned that I needed to add LogDateTime to the
GROUP BY...
Typical that I'd only just posted to see if I could get a few others to look
in this thread from yesterday as I wasn't sure if you'd return to this
message - and you've already solved it - lol - I'll get flamed now for
posting needlessly...hehe..sorry all :o)
Thanks muchly for the help - the website I'm creating is all about my new
born son, so its kinda important to me - thus appreciate the help even more
than usual :o)
Regards
Rob|||On Fri, 25 Nov 2005 23:31:09 GMT, Rob Meade wrote:
(snip)
> I'll get flamed now for
>posting needlessly...hehe..sorry all :o)
Hi Rob,
If you insist, I think I can arragne you being flamed. Do you want me to
call Celko over? ;->
Congratulations on your boy. Don't spend all your time building the
website - spend plenty time enjoying him. They grow up so fast.....
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Thursday, March 22, 2012
Distinct at two columns
I have this stored procedure:
ALTER PROCEDURE usp_My_Procedure
(
@.Country varchar(5)
)
AS
SELECT DISTINCT City, Short FROM Table1 WHERE Country = @.Country
RETURN
I want to select just one of each 'city' and 'short' in the database...But this is not working correct.....Whats wrong?
Lets say that I have a table that looks something like this
City Short
New York NY
Los Angeles LA
Lake Alice LA
Los Angeles LosAng
well ur code like this is anylized like give everything not repeated for these two columns,
try this
SELECT City, Short FROM Table1 WHERE Country = @.Country
and City in (SELECT DISTINCT City FROM Table1 WHERE Country = @.Country)
and Short in (SELECT DISTINCT short FROM Table1 WHERE Country = @.Country)
sqlWednesday, March 21, 2012
distibuted transations in linked server
please solve this problem.
when i am executing any transaction from one server to update record in other linked server database.
create PROCEDURE [dbo].[aTest]
@.iNum as int
AS
BEGIN
SET NOCOUNT ON;
begin tran
update aaa set sName='Deepak'
where iNum=@.iNum
exec [REPORTSRVR\SQL2005].HDFCCUSTOMER.dbo.aProc @.iNum
if @.@.error <> 0
begin
rollback tran
return
end
else
begin
commit tran
end
SET NOCOUNT OFF;
END
it shows following error
The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "REPORTSRVR\SQL2005" was unable to begin a distributed transaction.
1. Check/change your server option "remote proc trans" via sp_configure or Connections tab in SQL Server Instance Properties window
2. If you need MS DTC for distributed transactions: http://blogs.msdn.com/mab/archive/2005/12/30/508273.aspx
|||thanks for response.
i m using transaction statement. is it possible that single transaction can talk from two server?
Displaying values from Informix Stored Procedure
report preview, but I am able to see them in the Data window. I made sure
that I went in and mapped the fields for each dataset that I am using in the
report, but this still does not work. Any ideas?
TIA,
JeremyAnyone?
"Chancetribe" wrote:
> I am not able to see the values returned from my stored procedure in the
> report preview, but I am able to see them in the Data window. I made sure
> that I went in and mapped the fields for each dataset that I am using in the
> report, but this still does not work. Any ideas?
> TIA,
> Jeremysql
Sunday, March 11, 2012
Displaying print statements of Stored Procedures in SSIS Logs
Hi
I have few print statements in a stored procedure that gets called from the SSIS package. How do I make sure that these are captured in the SSIS log meaning how do I get them to be displayed in the Package Explorer window when running from the Business Intelligence Studio IDE.
Not possible. Print statements are diagnostic in nature and are not part of the returned data set, which is what gets exposed to SSIS.http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1229612&SiteID=1
Displaying Print Debugging from Stored Procedure immediately
Is there any way to force the message tab to display the messages mid execution?
One way is to use the raiserror command with a severity of 10 and a "with nowait" option. This will not cause an actual error to be raised, as you can see by running this code:
begin try
raiserror('Progress message', 10, 1) with nowait
end try
begin catch
print 'here'
end catch
Ron Rice
Displaying multiple records from one record
Hi there,
I've a complex stored procedure, which I'm trying to get a list of one or more users based the list of records that are being display. If I mentioned the overall store procedure here it'll turn you off, so I'll put the questions in bitesize chunks.
Example would be if Bob and Luke work for Acrm Corp and John for Maxwellarms Ltd, and there was an intimediate table which linked both. With my stored procedure I want to display both names in the same row as Acrm Corp. Is there a way to do this?
User table
Userid Username
1 Bob
2 Luke
3 John
Store procedure result
Companyname Username
Acrm Corp Null
Maxwellarm Ltd Null
Regards,
Since my last post, I found that the CMS is storing individual ids.
Still it would be nice to know how others are doing this.
An addition to my post above, I believe if I wanted more than one firstname and surname to appear in the columns, that I would have to create a different stored procedure retrieving the unique id from the first stored procedure.
Displaying messages to users
Hello,
I need some help coming up with a good concept for returning stored procedure messages to a user. Here is my setup:
Stored Proc:
@.ReturnCode INT - OUT
@.ReturnDetails VARCHAR(150) - OUT
If my stored procedure returns a value of less than 1 for the @.ReturnCode I want to display the error message in @.ReturnDetails, Now I have a DAL that returns back the @.ReturnCode to the codebehind ( via a function ) but how can i display the @.ReturnDetails to the user, I would like to use a javascript alert, I know how to display the message but my question is what is the best design for returning the message to the user?
I was thinking about passing in the caller when i instantiate my DAL, but I don't really like that idea, My other idea was have my function return a string like "-1|Invalid Password" and parsing it but don't like that either. Also is there a way to find out the page caller from my DAL? That would help a lot.
Your ideas are greatly appreciated.
Have you thought about having your DAL return a hashtable instead of just a return value? You could then do something like
string errorMessage;
if (int.Parse(myHashTable["ReturnValue"].ToString()) < 0)
// Return the error message to the users
errorMessage = myHashTable["ReturnMessage"].ToString();
Another alternative would be to pass a reference variable to your DAL, and populate this reference variable with the error message. Continue to use the integer return value, but have your DAL function populate the string with the return message to the user. You can then test the return value, and show the error if the return value is < 0. Try this:
string returnMessage ="";
if (MyDALFunction(ref returnMessage) < 0)
// Show your message
Response.Write(returnMessage);
Hope this helps...
Friday, March 9, 2012
Displaying HTML within an Access Report
Is it possible to remove the tags within a Stored Procedure so that it
displays nicely in an Access Report?
This is my SP:
ALTER PROCEDURE dbo.sp_Phat_Beats
AS SELECT fldcat, flddescript, fldtracklisting, fldprice, fldCategory
FROM dbo.tblProducts
WHERE (fldprice <> 0) AND (fldCategory = 17)
ORDER BY fldcat
fldtracklisting is the field that is HTML formatted. Any help would be
relly appreciated.
SteveHi
You could use replace multiple times to remove each tag, but this would
require embeded calls to the procedure one call per string you wish to
replace which could prove tedious. Check out replace in Books online
John
"Dooza" wrote:
> Is this possible? I have a column which has data with HTML formatting.
> Is it possible to remove the tags within a Stored Procedure so that it
> displays nicely in an Access Report?
> This is my SP:
> ALTER PROCEDURE dbo.sp_Phat_Beats
> AS SELECT fldcat, flddescript, fldtracklisting, fldprice, fldCategory
> FROM dbo.tblProducts
> WHERE (fldprice <> 0) AND (fldCategory = 17)
> ORDER BY fldcat
> fldtracklisting is the field that is HTML formatted. Any help would be
> relly appreciated.
> Steve
>
Displaying Dynamically created columns
I have a stored procedure that accepts input parameters and depending
on the input, returns multiple columns. For example depending on the month
range passed in, the stored procedure creates and populates temporary table
with columns for each month and returns the values in the temporary table.
How do I display these dynamically created columns using Reporting Services
(the number of coulmns returned by the stored proc varies between different
runs). Any help is appreciated.Sunil,
You would need to use the matrix control and then edit the
matrix_columngroup to use the data returned from your stored proc.
Hope this helps.
Bill Youngman
Anexinet, Inc.
"Sunil Oliver" <SunilOliver@.discussions.microsoft.com> wrote in message
news:D11DBA4E-C99F-4E37-8C0D-7F9D76192001@.microsoft.com...
> Hello,
> I have a stored procedure that accepts input parameters and
depending
> on the input, returns multiple columns. For example depending on the month
> range passed in, the stored procedure creates and populates temporary
table
> with columns for each month and returns the values in the temporary table.
> How do I display these dynamically created columns using Reporting
Services
> (the number of coulmns returned by the stored proc varies between
different
> runs). Any help is appreciated.
Wednesday, March 7, 2012
Displaying database name within select within UNION
diplay the database name where data is drawn from. I'm using 4
databases db1, db2, db3, db4 which all have the same table (Table1)
with identical column names (Surname, GivenNames).
CREATE PROCEDURE [dbo].[x_searchwildcard] @.varSurname VARChar(25)
AS
Select a.Surname, a.GivenNames
From [db1]..Table1 As a
Where a.Surname LIKE @.varSurname + '%'
UNION
Select a.Surname, a.GivenNames
From [db2]..Table1 As a
Where a.Surname LIKE @.varSurname + '%'
UNION
Select a.Surname, a.GivenNames
From [db3]..Table1 As a
Where a.Surname LIKE @.varSurname + '%'
UNION
Select a.Surname, a.GivenNames
From [db4]..Table1 As a
Where a.Surname LIKE @.varSurname + '%'
Order By a.Surname,a.GivenNames
GO
I tried the following
Select a.Surname, a.GivenNames, db_name()
However it only gave me the name of the database where the stored
procedure is kept (in my case 'Common')
I was hoping it would display results something like the following
Surname GivenNames Database
--- ---- ---
Fred Smith db1
Freddy Smith db2
Fred Smith db3
Fred Smithe db3
Fred Smith db4
Fred Smithye db4
Instead I receive
Surname GivenNames Database
--- ---- ---
Fred Smith common
Freddy Smith common
Fred Smith common
Fred Smithe common
Fred Smith common
Fred Smithye common
Any ideas?
Thanks
RickSelect a.Surname, a.GivenNames, 'db1' as 'Database'
From [db1]..Table1 As a
...
Select a.Surname, a.GivenNames, 'db2'
From [db2]..Table1 As a
Simon
Saturday, February 25, 2012
Displaying '$' currency in a graph
without a problem, except for the fact that it will not show a $ dollar
sign. I have tried using FormatCurrency() function on the value, but
it does not work. I have also tried just inserting a $ in front of the
vaue "$" & Fields!Total.Value, but it did not work either. Any
suggestions?
TwoNevermind, found it
Twobridge wrote:
> I am populating a graph from a stored procedure. My graph displays
> without a problem, except for the fact that it will not show a $ dollar
> sign. I have tried using FormatCurrency() function on the value, but
> it does not work. I have also tried just inserting a $ in front of the
> vaue "$" & Fields!Total.Value, but it did not work either. Any
> suggestions?
> Two
Friday, February 24, 2012
Display stored procedure results in a view
view. Something like this (although I know that this SQL doesn't work)...
CREATE VIEW vw_Equipment
AS
EXEC proc_Equipment_List
Thanks,
CraigYou could use OPENROWSET or OPENQUERY, like:
CREATE VIEW vw_Equipment
AS
SELECT ... FROM OPENQUERY(..., 'EXEC proc_Equipment_List')
I wouldn't use this for production code, though, I find it to be a bit of a
hack.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:061063E2-ADE5-420E-8D23-C48D7F3B29F0@.microsoft.com...
> If a stored procedure returns a table, is it possible to return that as a
> view. Something like this (although I know that this SQL doesn't work)...
> CREATE VIEW vw_Equipment
> AS
> EXEC proc_Equipment_List
>
> Thanks,
> Craig|||Hi Craig,
You just need to remember to set the dataaccess bit or the server to on
using the sp_serveroption. By default the server instance has data access
set off
Greg O
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:OgZC9EbmFHA.3816@.tk2msftngp13.phx.gbl...
> You could use OPENROWSET or OPENQUERY, like:
>
> CREATE VIEW vw_Equipment
> AS
> SELECT ... FROM OPENQUERY(..., 'EXEC proc_Equipment_List')
> I wouldn't use this for production code, though, I find it to be a bit of
> a hack.
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> Blog: http://solidqualitylearning.com/blogs/tibor/
>
> "Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
> news:061063E2-ADE5-420E-8D23-C48D7F3B29F0@.microsoft.com...
>|||Here is the example i just posted in another thread.
exec sp_serveroption 'srv','data access','true'
go
if object_id('_v','v') is not null
drop view _v
go
create view _v
as
select *
from openquery(srv,'set fmtonly off; exec sp_lock')x
go
select * from _v
go
-oj
"Craig HB" <CraigHB@.discussions.microsoft.com> wrote in message
news:061063E2-ADE5-420E-8D23-C48D7F3B29F0@.microsoft.com...
> If a stored procedure returns a table, is it possible to return that as a
> view. Something like this (although I know that this SQL doesn't work)...
> CREATE VIEW vw_Equipment
> AS
> EXEC proc_Equipment_List
>
> Thanks,
> Craig
Sunday, February 19, 2012
Display output parameters from stored procedure
Hi,
I have a report that uses a stored procedure. The stored procedure has 3 parameters 1 input and two output and also returns a resultset.
I have managed to hide the user prompt by changing the prompt for the two output parameters to an empty string.
The report runs fine and the user is not prompted for these two values, however the report does not show the values that are returned by these output parameters.
I could add extra fields to the resultset and not bother with the ouput parameters but this seems extremely inefficient as the resultset could contain several thousand rows and the fields would be the same for every single row.
Is it possible to display output paramater values?
Thanks In Advance
Chris
Chris,
have you thought of redesigning your stored procedure?
split it into two sp's, one containg the resultset, the second containg your output parameters, which should be redefined as "normal" parameters and brought back as a resultset via select @.parm1, @.parm2.
cheers,
Markus
Friday, February 17, 2012
Display Number of Records Processed
I've got a stored procedure that processes a TON of records...
What I would liek to do is to write a row to a "progress" table which shows how many rows have actually been processed.
I have a simple counter defined in the procedure:
SET @.COUNTER = 0
Each time the procedure loops through, it increments by 1:
SET @.COUNTER = @.COUNTER + 1
What I would like to do is write rows to a PROCESS table which would reads:
PROCESSED 1000 rows
PROCESSED 2000 rows
PROCESSED ...... rows
etc.
I have a slight idea how to pull this off, but not sure about the whole even number thing by 1000.
If anyone has any insight it would be greatly appreciated!!
Thanks in advance!
Do this:IF @.COUNTER % 1000 = 0
INSERT .......
|||Works like a charm!!!
Thanks Tom...