Showing posts with label build. Show all posts
Showing posts with label build. Show all posts

Friday, March 30, 2012

How can I consume webservices on SQL 2005

Hi,
I'd like know if can I build ( and how can do ) a store procedore on MS
SQL 2005 to access a remote webservices, process it and return the result to
my client ?
Thanks,
Solli M. Honório
Hello Solli,

> I'd like know if can I build ( and how can do ) a store procedore on
> MS SQL 2005 to access a remote webservices, process it and return the
> result to my client ?
Yes.
The real trick is that you need to add build step that generates a static
proxy class. Do that by adding this as a Post-build Event Step in your SqlClr
project:
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /force
"$(TargetPath)"
Note that you cannot use Visual Studio to deploy all of the needed assemblies.
You'll need to fire up SSMS or like and issue these commands:
use ...whatever database you like...
go
create assembly ...what you want to call your assembly...
from ...where the DLL is on your disk...
with permission_set = external_access
go
create assembly [...whatever your project name is... .XmlSerializers]
from '...where the DLL is on your disk...\SqlServerProject1.XmlSerializers.dll'
go
create procedure ...whatever you want to call the procedure...(...list of
parameters, if any...)
as external name Assembly Name.[fully qualified class name]. ...name of method...
go
exec ...whatever you called the procedure...
go
The guts of my stored procedure looks like:
[Microsoft.SqlServer.Server.SqlProcedure]
public static void WebMath(SqlInt32 x,SqlInt32 y)
{
SqlMetaData[] cols = new SqlMetaData[1];
cols[0] = new SqlMetaData("Result", SqlDbType.Int);
SqlDataRecord rec = new SqlDataRecord(cols);
using (SqlServerProject1.ws1proxy.ws1 proxy = new SqlServerProject1.ws1proxy.ws1())
{
rec.SetInt32(0, proxy.AddTwo(x.Value, y.Value));
SqlContext.Pipe.Send(rec);
}
}
The Web Service in question looks like:
public int AddTwo(int x,int y) {
return(x+y);
}
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/

How can I consume webservices on SQL 2005

Hi,
I'd like know if can I build ( and how can do ) a store procedore on MS
SQL 2005 to access a remote webservices, process it and return the result to
my client ?
Thanks,
Solli M. HonórioHello Solli,

> I'd like know if can I build ( and how can do ) a store procedore on
> MS SQL 2005 to access a remote webservices, process it and return the
> result to my client ?
Yes.
The real trick is that you need to add build step that generates a static
proxy class. Do that by adding this as a Post-build Event Step in your SqlCl
r
project:
"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe" /force
"$(TargetPath)"
Note that you cannot use Visual Studio to deploy all of the needed assemblie
s.
You'll need to fire up SSMS or like and issue these commands:
use ...whatever database you like...
go
create assembly ...what you want to call your assembly...
from ...where the DLL is on your disk...
with permission_set = external_access
go
create assembly [...whatever your project name is... .XmlSerializers]
from '...where the DLL is on your disk...\SqlServerProject1.XmlSerializers.d
ll'
go
create procedure ...whatever you want to call the procedure...(...list of
parameters, if any...)
as external name Assembly Name.[fully qualified class name]. ...name of meth
od...
go
exec ...whatever you called the procedure...
go
The guts of my stored procedure looks like:
[Microsoft.SqlServer.Server.SqlProcedure]
public static void WebMath(SqlInt32 x,SqlInt32 y)
{
SqlMetaData[] cols = new SqlMetaData[1];
cols[0] = new SqlMetaData("Result", SqlDbType.Int);
SqlDataRecord rec = new SqlDataRecord(cols);
using (SqlServerProject1.ws1proxy.ws1 proxy = new SqlServerProject1.ws1proxy
.ws1())
{
rec.SetInt32(0, proxy.AddTwo(x.Value, y.Value));
SqlContext.Pipe.Send(rec);
}
}
The Web Service in question looks like:
public int AddTwo(int x,int y) {
return(x+y);
}
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/sql

Wednesday, March 28, 2012

How can I clear active connections without disabling the database?

To better explain the question let me build a scenario.
If someone is connected to the database there is an active connection, which does appear in Management Studio. If we try to do a restore of the database, SQL gives us a message saying that it cannot gain exclusive access to the database and the restore fails. To gain exclusive access to the database we need to clear the active connections.
Currently in Management Studio the only ways that I have found to clear the connections are to take the database offline or detach the database completely. What I would like to know is if there is another way to clear the active connections without have to take the database offline or detach it?
In SQL 2000 I could right-click the database, select all tasks, and then select detach database and click clear connections. Of course I would then have to make sure I clicked cancel otherwise I would mistakenly detach the database. This would clear the connections without taking the database offline.
If the only option in Management Studio to clear the connections is to disable the database I would like to request an option under tasks called clear connections. This way the server administrator could click on this to see the current active connections and clear them, either individually, or all of them without having to take the database offline or detach it.
Thanks in advance!

There are several ways you can do this without having to detach the database.
1. run sp_who2 to see all the SPIDs connected to your database. For each SPID, execute kill <spid #>

2. In Object Explorer, Click on Management -> Activity Monitor. RIght-click, select View Processes. From there, you can filter the proccesses any way you want, even by database. After that, you can right-click on each process and select Kill Process.
While it's not a one-shot command, you do have much more control over who gets disconnected.
|||I tried what you suggested and it works. I was curious still though if there are any plans to add a clear connections options that will allow us to clear all connections to a database with one click of a button, similar to SQL 2000.
sql

Friday, March 23, 2012

How can I browse the tree graph in DataMining DecisionTrees by C# coding ?

I build my DataMining DecisionTrees in SQL Server 2005.

How can I get the tree graph in DataMining DecisionTrees by C# coding ?

Start by adding a reference to Microsoft.AnalysisServices.AdomdClient

Then, create a new AdomdConnection and connect to the server:
AdomdConnection cn = new AdomdConnection();
cn.ConnectionString = "Data Source=localhost; Initial Catalog=MyDatabase"
cn.Open();

Continue by creating a Command object, associated with the connection
AdomdCommand cmd = new AdomdCommand(); cmd.Connection = cn;

Using the command object, you can now issue queries. A query like:
SELECT * FROM MyModel.CONTENT
will return all the content nodes, for all the trees in the model (there is one tree for each predictable attribute of the model)
Now, each node has multiple properties, returned by the query above as columns. Particularly important for the tree structure are the NODE_UNIQUE_NAME and the PARENT_UNIQUE_NAME columns. NODE_UNIQUE_NAME is a unique identifier of each node, PARENT_UNIQUE_NAME is the unique identifier of the parent. You can use this relationship to build the tree structure.

The content has one root node, which represents the mining model. This node is the first one returned by the SELECT * FROM Model.CONTENT query, it has PARENT_UNIQUE_NAME empty and the NODE_TYPE property has the value of 1. This node should not appear in the tree visualizer.

Its descendants are the root nodes for all the trees built by the mining model. These are direct children of the root node and have NODE_TYPE = 2.
The NODE_UNIQUE_NAME/PARENT_UNIQUE_NAME should be enough to build the rest of the tree.

Now, each node has a NODE_DISTRIBUTION property, returned by the query as a nested table (if you use cmd.ExecuteReader to get the query results, you will get an AdomdDataReader object for the result and you can use the GetDataReader method to obtain a reader for the nested table). The NODE_DISTRIBUTION table contains the distribution for each node. If the tree is a regression tree (continuous target), the NODE_DISTRIBUTION for the leafs contains the regression formula coefficients

Hope this helps,

|||Very very helpful, thanks a lot|||

Microsoft.AnalysisServices.Controls.DLL

Microsoft.AnalysisServices.Viewers.DLL

Microsoft.DataWarehouse.DLL

How can I be notified when record is updated

I want to build an windows application by using a visual C# to Notify the user that his data in the database had been changed ..such like "New Message In Your Mail Box Alert"..So I need to know if there is way that to let the SQL Server send a notify (just like Trigger) ..

osmansays,
Combine a trigger and a stored procedure to send a email on updates
--------------------------------
Procedure like :
Create Procedure sp_SMTPMail
@.SenderName varchar(100),
@.SenderAddress varchar(100),
@.RecipientName varchar(100),
@.RecipientAddress varchar(100),
@.Subject varchar(200),
@.Body varchar(8000),
@.MailServer varchar(100) = 'localhost'
AS

SET nocount on
declare @.oMail int
declare @.resultcode int
EXEC @.resultcode = sp_OACreate 'SMTPsvg.Mailer', @.oMail OUT
if @.resultcode = 0
BEGIN
EXEC @.resultcode = sp_OASetProperty @.oMail, 'RemoteHost', @.mailserver
EXEC @.resultcode = sp_OASetProperty @.oMail, 'FromName', @.SenderName
EXEC @.resultcode = sp_OASetProperty @.oMail, 'FromAddress', @.SenderAddress
EXEC @.resultcode = sp_OAMethod @.oMail, 'AddRecipient', NULL, @.RecipientName, @.RecipientAddress
EXEC @.resultcode = sp_OASetProperty @.oMail, 'Subject', @.Subject
EXEC @.resultcode = sp_OASetProperty @.oMail, 'BodyText', @.Body
EXEC @.resultcode = sp_OAMethod @.oMail, 'SendMail', NULL
EXEC sp_OADestroy @.oMail
END
SET nocount off
--------------------------------
Trigger like :
CREATE TRIGGER trgDataChanged on tblData
AFTER UPDATE
AS
BEGIN
exec sp_SMTPMail @.SenderName='me', @.SenderAddress='me@.somewhere.com', @.RecipientName = 'Someone', @.RecipientAddress = 'someone@.someplace.com', @.Subject='SQL Data Change', @.body='data in table tblData has been changed'
END
--------------------------------
If you also want to track the changes you can either translate the query to simple data or show the data that is changed but to view that you need to walk through the recordset with for instance a cursor.
Peter

Monday, March 19, 2012

how can build two tabels together with ms sql query

Hello to all,

I have now two tabels ( Ta and Tb). the tabel includes difference attributte. I want to build this two tables together.

I used this query:

select * from Ta where Ta.Id = @.ID union all select * from Tb where Tb.IdOfa = @.ID

but it doesn't work and the following error message comes

"All inquiries in an SQL application, which contain a union operator, must contain directly many expressions in their goal lists "

Can someone help me?

Thanks

best Regards

pinsha

Please post some sample data from each table and the result you are expecting out of your query.|||

Hi Pinsha,

While using Union Operator you must have the equal number of columns in both query.

You have written Select * Query 1 Union Select * Query 2

Please check if the number of columns are same in both the queries. ( I mean in both the tables as they are used in queries )

Satya

|||

satya_tanwar:

Please check if the number of columns are same in both the queries. ( I mean in both the tables as they are used in queries )

And the columns should be ofsimilardatatype.

|||

Off Course Bro...Stick out tongue

Satya

Friday, March 9, 2012

How are Execution Paths built?

Lets say you create a view.

then you select from that view for the first time. with no where clause.

Does it build a different execution path than it does if you select from that view with a where clause?

Hi,

Dynamic SQL statements are parameterized if possible (simple where ID = 5 might be cached as ID = ?) or the exact query text is used as a reference. So querying against your view with different criteria will generate different query plans.

WesleyB

Visit my SQL Server weblog @. http://dis4ea.blogspot.com

|||Think of a view as basically a "macro" which inserts the view's select statement into your code at execution time. The execution plan is created when you use the view.

So, yes, the execution plan is different based on your where clause.

|||so would you say its better to have your first query against a view not have a where clause?
|||No. There is no reason to run a query on a view with no where clause. The execution plan is recreated every time the view is used.

|||I am not saying you are incorrect and i do appreciate your comments, but the first time i use a view it takes a little longer than all the other times i use the view. I understand this to be because it is building the Execution path and optimizing the views Execution path.|||

Yes, it would be slower the first time because of creating the execution plan. And it will use the same execution plan for similar where statements.

But, running a view with no where does nothing, unless you do that over and over. If you put in a "WHERE field=x" it creates an execution plan based on that. Then if you do "WHERE field2=y" it makes a new exeuction plan. It MIGHT have the plan cached if you have used a similar plan before, but you can't count on it.

|||

Thank you sir,

That answer helps me unserstand immensely. so it builds a different Execution path per each unquely patterened where clause..

Friday, February 24, 2012

Hotfix 934459.

Hi, I have a sql 2005 with Sp2 applied. My Build is 9.0.3054
Now I have the error described in Fix 934459 (The Check Database Integrity
task and the Execute T-SQL Statement task in a maintenance plan may lose
database context in certain circumstances ), but my build 9.0.3054 doesn't
seem to be in the affected ones..
Should I install the hotfix? Which one?
This are the two available
If you are running a build of SQL Server 2005 SP2 between 3150 and 3158
http://support.microsoft.com/kb/934459/
If you are running any build of SQL Server 2005 SP2 between 3042 and 3053
http://support.microsoft.com/kb/934458/
Thanks.
You should get 3200 or, better yet, 3215 instead.
9.0.3200:
http://support.microsoft.com/kb/941450
9.0.3215:
http://support.microsoft.com/kb/943656
"averied" <averied@.discussions.microsoft.com> wrote in message
news:BE40CE77-C3A5-4FF3-AEFA-477950543802@.microsoft.com...
> Hi, I have a sql 2005 with Sp2 applied. My Build is 9.0.3054
> Now I have the error described in Fix 934459 (The Check Database Integrity
> task and the Execute T-SQL Statement task in a maintenance plan may lose
> database context in certain circumstances ), but my build 9.0.3054 doesn't
> seem to be in the affected ones..
> Should I install the hotfix? Which one?
> This are the two available
> If you are running a build of SQL Server 2005 SP2 between 3150 and 3158
> http://support.microsoft.com/kb/934459/
> If you are running any build of SQL Server 2005 SP2 between 3042 and 3053
> http://support.microsoft.com/kb/934458/
>
> Thanks.
>
|||I installed the Cumulative update package 4 for SQL Server 2005 Service Pack
2 and rebooted my machine, yet my version still shows 9.00.3042. The
installation appeared to function properly w/ no errors. How can I tell that
this hot fix did indeed install?
Cordially,
Mark Boettcher
PS, I have just now requested the hotfix for 3215 and should get it tomorrow.
"Aaron Bertrand [SQL Server MVP]" wrote:

> You should get 3200 or, better yet, 3215 instead.
> 9.0.3200:
> http://support.microsoft.com/kb/941450
> 9.0.3215:
> http://support.microsoft.com/kb/943656
>
>
> "averied" <averied@.discussions.microsoft.com> wrote in message
> news:BE40CE77-C3A5-4FF3-AEFA-477950543802@.microsoft.com...
>
>
|||>I installed the Cumulative update package 4 for SQL Server 2005 Service
>Pack
> 2 and rebooted my machine, yet my version still shows 9.00.3042.
Where/how are you checking "my version"?
A
|||In server management studio, I right-clicked on registered server and found
it under properties. If not there, how should I display the sql version?
Mark
"Aaron Bertrand [SQL Server MVP]" wrote:

> Where/how are you checking "my version"?
> A
>
|||That is the version for the tools (Management Studio). Open a query window
connected to the server you updated, and then run:
SELECT @.@.VERSION;
"Mark Boettcher" <MarkBoettcher@.discussions.microsoft.com> wrote in message
news:71D22B9E-5D0B-4B79-8E59-B9067A58EC2C@.microsoft.com...[vbcol=seagreen]
> In server management studio, I right-clicked on registered server and
> found
> it under properties. If not there, how should I display the sql version?
> Mark
> "Aaron Bertrand [SQL Server MVP]" wrote:
|||Since I installed Cumulative update package 4, I requested, received, and
installed Cumulative update package 5. Using the Select @.@.Version command
returns 9.00.3215 now. I assume Cumulative update package 5 includes the
changes in Cumulative update package 4 - correct? After I installed package
4, I did do a select @.@.version and received 9.00.3042 which is why I
questioned whether the package really did install.
Mark
"Aaron Bertrand [SQL Server MVP]" wrote:

> That is the version for the tools (Management Studio). Open a query window
> connected to the server you updated, and then run:
> SELECT @.@.VERSION;
>
> "Mark Boettcher" <MarkBoettcher@.discussions.microsoft.com> wrote in message
> news:71D22B9E-5D0B-4B79-8E59-B9067A58EC2C@.microsoft.com...
>
|||> returns 9.00.3215 now. I assume Cumulative update package 5 includes the
> changes in Cumulative update package 4 - correct?
Yes, each cumulative update page states that cumulative updates are
cumulative -- that's why they're named as such. :-)

> After I installed package
> 4, I did do a select @.@.version and received 9.00.3042
Then the install didn't succeed, or you ran SELECT @.@.VERSION against the
wrong server.
A

Hotfix 934459.

Hi, I have a sql 2005 with Sp2 applied. My Build is 9.0.3054
Now I have the error described in Fix 934459 (The Check Database Integrity
task and the Execute T-SQL Statement task in a maintenance plan may lose
database context in certain circumstances ), but my build 9.0.3054 doesn't
seem to be in the affected ones..
Should I install the hotfix' Which one'
This are the two available
If you are running a build of SQL Server 2005 SP2 between 3150 and 3158
http://support.microsoft.com/kb/934459/
If you are running any build of SQL Server 2005 SP2 between 3042 and 3053
http://support.microsoft.com/kb/934458/
Thanks.You should get 3200 or, better yet, 3215 instead.
9.0.3200:
http://support.microsoft.com/kb/941450
9.0.3215:
http://support.microsoft.com/kb/943656
"averied" <averied@.discussions.microsoft.com> wrote in message
news:BE40CE77-C3A5-4FF3-AEFA-477950543802@.microsoft.com...
> Hi, I have a sql 2005 with Sp2 applied. My Build is 9.0.3054
> Now I have the error described in Fix 934459 (The Check Database Integrity
> task and the Execute T-SQL Statement task in a maintenance plan may lose
> database context in certain circumstances ), but my build 9.0.3054 doesn't
> seem to be in the affected ones..
> Should I install the hotfix' Which one'
> This are the two available
> If you are running a build of SQL Server 2005 SP2 between 3150 and 3158
> http://support.microsoft.com/kb/934459/
> If you are running any build of SQL Server 2005 SP2 between 3042 and 3053
> http://support.microsoft.com/kb/934458/
>
> Thanks.
>|||I installed the Cumulative update package 4 for SQL Server 2005 Service Pack
2 and rebooted my machine, yet my version still shows 9.00.3042. The
installation appeared to function properly w/ no errors. How can I tell that
this hot fix did indeed install?
Cordially,
Mark Boettcher
PS, I have just now requested the hotfix for 3215 and should get it tomorrow.
"Aaron Bertrand [SQL Server MVP]" wrote:
> You should get 3200 or, better yet, 3215 instead.
> 9.0.3200:
> http://support.microsoft.com/kb/941450
> 9.0.3215:
> http://support.microsoft.com/kb/943656
>
>
> "averied" <averied@.discussions.microsoft.com> wrote in message
> news:BE40CE77-C3A5-4FF3-AEFA-477950543802@.microsoft.com...
> > Hi, I have a sql 2005 with Sp2 applied. My Build is 9.0.3054
> >
> > Now I have the error described in Fix 934459 (The Check Database Integrity
> > task and the Execute T-SQL Statement task in a maintenance plan may lose
> > database context in certain circumstances ), but my build 9.0.3054 doesn't
> > seem to be in the affected ones..
> >
> > Should I install the hotfix' Which one'
> >
> > This are the two available
> >
> > If you are running a build of SQL Server 2005 SP2 between 3150 and 3158
> > http://support.microsoft.com/kb/934459/
> >
> > If you are running any build of SQL Server 2005 SP2 between 3042 and 3053
> > http://support.microsoft.com/kb/934458/
> >
> >
> > Thanks.
> >
>
>|||>I installed the Cumulative update package 4 for SQL Server 2005 Service
>Pack
> 2 and rebooted my machine, yet my version still shows 9.00.3042.
Where/how are you checking "my version"?
A|||In server management studio, I right-clicked on registered server and found
it under properties. If not there, how should I display the sql version?
Mark
"Aaron Bertrand [SQL Server MVP]" wrote:
> >I installed the Cumulative update package 4 for SQL Server 2005 Service
> >Pack
> > 2 and rebooted my machine, yet my version still shows 9.00.3042.
> Where/how are you checking "my version"?
> A
>|||That is the version for the tools (Management Studio). Open a query window
connected to the server you updated, and then run:
SELECT @.@.VERSION;
"Mark Boettcher" <MarkBoettcher@.discussions.microsoft.com> wrote in message
news:71D22B9E-5D0B-4B79-8E59-B9067A58EC2C@.microsoft.com...
> In server management studio, I right-clicked on registered server and
> found
> it under properties. If not there, how should I display the sql version?
> Mark
> "Aaron Bertrand [SQL Server MVP]" wrote:
>> >I installed the Cumulative update package 4 for SQL Server 2005 Service
>> >Pack
>> > 2 and rebooted my machine, yet my version still shows 9.00.3042.
>> Where/how are you checking "my version"?
>> A|||Since I installed Cumulative update package 4, I requested, received, and
installed Cumulative update package 5. Using the Select @.@.Version command
returns 9.00.3215 now. I assume Cumulative update package 5 includes the
changes in Cumulative update package 4 - correct? After I installed package
4, I did do a select @.@.version and received 9.00.3042 which is why I
questioned whether the package really did install.
Mark
"Aaron Bertrand [SQL Server MVP]" wrote:
> That is the version for the tools (Management Studio). Open a query window
> connected to the server you updated, and then run:
> SELECT @.@.VERSION;
>
> "Mark Boettcher" <MarkBoettcher@.discussions.microsoft.com> wrote in message
> news:71D22B9E-5D0B-4B79-8E59-B9067A58EC2C@.microsoft.com...
> > In server management studio, I right-clicked on registered server and
> > found
> > it under properties. If not there, how should I display the sql version?
> >
> > Mark
> >
> > "Aaron Bertrand [SQL Server MVP]" wrote:
> >
> >> >I installed the Cumulative update package 4 for SQL Server 2005 Service
> >> >Pack
> >> > 2 and rebooted my machine, yet my version still shows 9.00.3042.
> >>
> >> Where/how are you checking "my version"?
> >>
> >> A
> >>
>|||> returns 9.00.3215 now. I assume Cumulative update package 5 includes the
> changes in Cumulative update package 4 - correct?
Yes, each cumulative update page states that cumulative updates are
cumulative -- that's why they're named as such. :-)
> After I installed package
> 4, I did do a select @.@.version and received 9.00.3042
Then the install didn't succeed, or you ran SELECT @.@.VERSION against the
wrong server.
A