Monday, March 19, 2012
CLR user defined aggregate function (SS2005)
In a user defined aggregate in Visual Studio 2005 with SQL Server 2005, I
declared a private variable in the struct and initialized in the Init "event
"
of the aggregate.
In the Terminate "event" it turned out that the variable was out of scope
(null).
My first thought was that this happened as a result of reads and writes of
intermediate results of the aggregate function, where (in my case) the
private variable was not explicitly saved.
But this idea is not consistent with the Merge "event" that also uses the
private variable and there it never is out of scope.
Who can explain?
Thx.examnotes <Axford@.discussions.microsoft.com> wrote in
news:B7150A1D-2067-4377-8483-090BB56A7023@.microsoft.com:
> In a user defined aggregate in Visual Studio 2005 with SQL Server
> 2005, I declared a private variable in the struct and initialized in
> the Init "event" of the aggregate.
> In the Terminate "event" it turned out that the variable was out of
> scope (null).
> My first thought was that this happened as a result of reads and
> writes of intermediate results of the aggregate function, where (in my
> case) the private variable was not explicitly saved.
> But this idea is not consistent with the Merge "event" that also uses
> the private variable and there it never is out of scope.
How do you establish that the variable is not null in the Merge method?
In other words, are you certain that the Merge is being called. SQL will
not call Merge unless it creates a new instance of your aggregate and
runs that instance in parallell over a group in your accumulation.
Anyway, can you please post the code for your aggregate and we'll have a
look.
Also, it'd probably be better is you posted this in the sqlserver.clr
group which deals explicitly with SQLCLR issues. I will x-post this
reply to there.
Niels
****************************************
**********
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@.no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
****************************************
**********|||Sorry it was the Accumulate event where the private variable was in scope. S
o
probably the Merge event will set it to null also. Can I enforce thecall to
Merge in some way?
I cannot find a group sqlserver.clr.
Thanks for the reply.
"Niels Berglund" wrote:
> examnotes <Axford@.discussions.microsoft.com> wrote in
> news:B7150A1D-2067-4377-8483-090BB56A7023@.microsoft.com:
>
>
> How do you establish that the variable is not null in the Merge method?
> In other words, are you certain that the Merge is being called. SQL will
> not call Merge unless it creates a new instance of your aggregate and
> runs that instance in parallell over a group in your accumulation.
> Anyway, can you please post the code for your aggregate and we'll have a
> look.
> Also, it'd probably be better is you posted this in the sqlserver.clr
> group which deals explicitly with SQLCLR issues. I will x-post this
> reply to there.
>
> Niels
> --
> ****************************************
**********
> * Niels Berglund
> * http://staff.develop.com/nielsb
> * nielsb@.no-spam.develop.com
> * "A First Look at SQL Server 2005 for Developers"
> * http://www.awprofessional.com/title/0321180593
> ****************************************
**********
>|||examnotes <Axford@.discussions.microsoft.com> wrote in
news:FC2366AE-AFFD-4AD9-8E03-680568F1C497@.microsoft.com:
> Sorry it was the Accumulate event where the private variable was in
> scope. So probably the Merge event will set it to null also. Can I
> enforce thecall to Merge in some way?
OK, so in Accumulate the variable is OK, but in Terminate it is null -
is that correct? If so, please post the code for your UDA. AFAIK, you
can not force a call for Merge.
> I cannot find a group sqlserver.clr.
Do a refresh of your newsgroup list - that should make it available to
you (microsoft.public.sqlserver.clr).
Niels
****************************************
**********
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@.no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
****************************************
**********|||Here you go with the code (it is from Microsoft samples):
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedAggregate(
Format.UserDefined,MaxByteSize=8000, IsInvariantToNulls=true,
IsInvariantToDuplicates = false, IsInvariantToOrder=true,
IsNullIfEmpty=true)]
public struct Concatenate : IBinarySerialize
{
private string delimeter;
private StringBuilder intermediateResult;
public void Init()
{
delimeter = "-";
intermediateResult = new StringBuilder();
}
public void Accumulate(SqlString value)
{
if (value.IsNull)
return;
intermediateResult.Append(value.Value).Append(delimeter);
}
public void Merge(Concatenate other)
{
intermediateResult.Append(other.intermediateResult).Append(delimeter);
}
public SqlString Terminate()
{
string output = string.Empty;
if (this.intermediateResult != null
&& this.intermediateResult.Length > 0)
{
output = this.intermediateResult.ToString(0,
this.intermediateResult.Length - 1);
}
return new SqlString(output);
}
#region IBinarySerialize Members
void IBinarySerialize.Read(System.IO.BinaryReader r)
{
intermediateResult = new StringBuilder(r.ToString());
}
void IBinarySerialize.Write(System.IO.BinaryWriter w)
{
w.Write(intermediateResult.ToString());
}
#endregion
}
"Niels Berglund" wrote:
> examnotes <Axford@.discussions.microsoft.com> wrote in
> news:FC2366AE-AFFD-4AD9-8E03-680568F1C497@.microsoft.com:
>
> OK, so in Accumulate the variable is OK, but in Terminate it is null -
> is that correct? If so, please post the code for your UDA. AFAIK, you
> can not force a call for Merge.
>
> Do a refresh of your newsgroup list - that should make it available to
> you (microsoft.public.sqlserver.clr).
> Niels
> --
> ****************************************
**********
> * Niels Berglund
> * http://staff.develop.com/nielsb
> * nielsb@.no-spam.develop.com
> * "A First Look at SQL Server 2005 for Developers"
> * http://www.awprofessional.com/title/0321180593
> ****************************************
**********
>
Sunday, March 11, 2012
CLR SP debugging problem
Hi All,
Could you please help me?
I have a problem with T-SQL stored procedure, which call the CLR Stored Procedure, and when it runs into it my Visual Studio gets berserk, looping like crazy, eating 100% CPU and gobling off more and more memory. The Visual Studio out into the the Output window the following message over and over again:
WARNING: Debugger was accessing T-SQL variables while managed code was not suspended. Waiting until the access is done to continue T-SQL execution.Continueing T-SQL execution.
WARNING: Debugger was accessing T-SQL variables while managed code was not suspended. Waiting until the access is done to continue T-SQL execution.Continueing T-SQL execution.
The only way to stop it is by killing the Visual Studio process. Then I have to stop, or sometimes even kill the SQL server to bring the CPU down from 100%.
What should I do to avoid this problem? Thank you very much for the help.
Does this problem reproduce consistently? This is likely to be a known issue with debugging while in parallel execution. Can you try setting MAXDOP(1) and see if that solves the problem?
If not, can you paste the code you're using that's hitting this?
Thanks,
Steven
|||The problem was in the test data. My CLR procedure processes regular expressions. The pattern for regular expression has been written incorrectly and because of it there was an error in debug process. After I have corrected a pattern of regular expression a problem have left.
Thank you for the consideration,
Sveta
CLR Question (BASIC)
System.Data.SQLServer that I need Visual Studio 2005 to develop CLR apps for
SQL?Hello RSH,
> I have Visual Studio .Net 2003...I am assuming that since it can't
> find System.Data.SQLServer that I need Visual Studio 2005 to develop
> CLR apps for SQL?
Correct
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||There's no System.Data.SQLServer anymore. You use the regular connection obj
ects, reader etc. For
SQLCLR specific things (like context and pipe), you use the Microsoft.SqlSer
ver.Server namespace.
You do need Framework 2.0 (as the things you need are in the System.Data.dll
file that comes with
Framework 2.0). You can download Framework 2.0 and write your CLR objects us
ing Notepad and
command-line compile them. If you want to use VS to write SQLCLR objects you
need VS 2005.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"RSH" <way_beyond_oops@.yahoo.com> wrote in message news:ejDCfJ29FHA.160@.TK2MSFTNGP12.phx.gb
l...
>I have Visual Studio .Net 2003...I am assuming that since it can't find Sys
tem.Data.SQLServer that
>I need Visual Studio 2005 to develop CLR apps for SQL?
>|||You don't really need Visual Studio at all. You can download the .NET 2.0
SDK and use the command-line tools. But if you want the IDE experience,
yes, VS2005 is necessary.
Adam Machanic
Pro SQL Server 2005, available now
http://www.apress.com/book/bookDisplay.html?bID=457
--
"RSH" <way_beyond_oops@.yahoo.com> wrote in message
news:ejDCfJ29FHA.160@.TK2MSFTNGP12.phx.gbl...
>I have Visual Studio .Net 2003...I am assuming that since it can't find
>System.Data.SQLServer that I need Visual Studio 2005 to develop CLR apps
>for SQL?
>
Thursday, March 8, 2012
CLR Deployment
I'm attempting to deploy CLR Stored Procedures from Visual Studio 2005.
I have a VS Database project with stored procedures for all of the tables in our database. (I would really like to keep everything together in 1 DLL), everything seems fine except...
I keep receiving the following error when attempting to deploy to SQL Server:
Error 1 Timeout expired. The timeout period elapsed prior to completion of
the operation or the server is not responding.
After some experimentation I have determined that its because the DLL is too
large: 1.8 mb. (I also have a larger one).
I have looked through various documentation sources but have found none
concerning this problem other than specifing something aboug a 100ms
execution timeout (not sure if this is the same).
Deployment works if I trim down the size of the DLL (i.e., remove procedures from the solution)
Is there anyway to deploy large DLLs to SQL Server without having to break
them up? If so, where is the setting to allow a longer timeout period for
deployment?
Thanks for the reply.
Yes I know I could do that, but it is so much easier to use VS.
Also the major time consuming problem is the number of tables and procedures.
Heres the scenario.
We have 2 databases, 1 flat, 1 relational. (Same problem is occuring on both).
The flat database has been imported from FoxPro 2.6 DBF's for conversion into the relational to supply historic data to an application upgrade. Needless to say there are a large number of tables. I have utilized ApexSQL to generate CLR Stored Procedues for each table. (i.e., INSERT,UPDATE,DELETE,SELECT, and so on...)
VS Compiles the source with no errors, it is just during deployment to SQL Server. As a work around for now I have split the .CS files into somewhat logical groups and created a seperate VS solution for each, all of these deploy with no problems.
For documentation and maintenance I would rather keep everything together in one VS Solution for each Database.
Again thanks for your reply.
Glenn
CLR Deployment
I'm attempting to deploy CLR Stored Procedures from Visual Studio 2005.
I have a VS Database project with stored procedures for all of the tables in our database. (I would really like to keep everything together in 1 DLL), everything seems fine except...
I keep receiving the following error when attempting to deploy to SQL Server:
Error 1 Timeout expired. The timeout period elapsed prior to completion of
the operation or the server is not responding.
After some experimentation I have determined that its because the DLL is too
large: 1.8 mb. (I also have a larger one).
I have looked through various documentation sources but have found none
concerning this problem other than specifing something aboug a 100ms
execution timeout (not sure if this is the same).
Deployment works if I trim down the size of the DLL (i.e., remove procedures from the solution)
Is there anyway to deploy large DLLs to SQL Server without having to break
them up? If so, where is the setting to allow a longer timeout period for
deployment?
Thanks for the reply.
Yes I know I could do that, but it is so much easier to use VS.
Also the major time consuming problem is the number of tables and procedures.
Heres the scenario.
We have 2 databases, 1 flat, 1 relational. (Same problem is occuring on both).
The flat database has been imported from FoxPro 2.6 DBF's for conversion into the relational to supply historic data to an application upgrade. Needless to say there are a large number of tables. I have utilized ApexSQL to generate CLR Stored Procedues for each table. (i.e., INSERT,UPDATE,DELETE,SELECT, and so on...)
VS Compiles the source with no errors, it is just during deployment to SQL Server. As a work around for now I have split the .CS files into somewhat logical groups and created a seperate VS solution for each, all of these deploy with no problems.
For documentation and maintenance I would rather keep everything together in one VS Solution for each Database.
Again thanks for your reply.
Glenn
Wednesday, March 7, 2012
CLR Assembly redeploy problem.
define functions using Visual Studio 2005, and I have used Visual
Studio to deploy the assembly to a SQL Server 2005 instance
successfully, of course these sps and udfs are used by other T-SQL sps
and udfs. Now the assembly has a new version, and I want to use it to
replace the original one, but when I use Visual Studio 2005 to deploy
the new assembly, the following error occurs:
Error1Cannot drop the function 'TranslationStringLike', because it
does not exist or you do not have permission.
Cannot drop the function 'TranslateEngString', because it does not
exist or you do not have permission.
Cannot drop the function 'TranslateEngStringReverse', because it does
not exist or you do not have permission.
DROP ASSEMBLY failed because 'FirmBankCLR' is referenced by object
'TranslationStringLike'.FirmBankCLR
That is the assembly is dependent by other objects, it can't be
dropped until it is not dependent by other objects. How can I resolve
this problem using Visual Studio 2005 or something else?Amber (guxiaobo1982@.gmail.com) writes:
Quote:
Originally Posted by
I have created a C# library containing CLR stored procedures and user-
define functions using Visual Studio 2005, and I have used Visual
Studio to deploy the assembly to a SQL Server 2005 instance
successfully, of course these sps and udfs are used by other T-SQL sps
and udfs. Now the assembly has a new version, and I want to use it to
replace the original one, but when I use Visual Studio 2005 to deploy
the new assembly, the following error occurs:
>
Error 1 Cannot drop the function 'TranslationStringLike', because
it does not exist or you do not have permission. Cannot drop the
function 'TranslateEngString', because it does not exist or you do not
have permission. Cannot drop the function 'TranslateEngStringReverse',
because it does not exist or you do not have permission. DROP ASSEMBLY
failed because 'FirmBankCLR' is referenced by object
'TranslationStringLike'. FirmBankCLR
>
That is the assembly is dependent by other objects, it can't be
dropped until it is not dependent by other objects. How can I resolve
this problem using Visual Studio 2005 or something else?
As long as the interface of the assembly does not change, you can just
do ALTER ASSEMBLY. Either specify directly, which is simple if the DLL
is accessible from SQL Server. Or specify the DLL as a hexstring directly
in the ALTER ASSEMBLY statement.
If the interface has changed, you will need to drop all functions
created from it, as well as dependent assemblies.
I learnt just the other day that ALTER ASSEMBLY is not in the repetoir
of Visual Studio. I don't use Visual Studio to work with assemblies
but stick to the command line. And all impression I get is that
using Visual Studio just makes things harder.
--
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|||
Quote:
Originally Posted by
I learnt just the other day that ALTER ASSEMBLY is not in the repetoir
of Visual Studio. I don't use Visual Studio to work with assemblies
but stick to the command line. And all impression I get is that
using Visual Studio just makes things harder.
It seems Microsoft hasn't done the job well, but if we have a lot of
objects in the assembly, the manual process of dropping and creating
them is horrible.|||Amber (guxiaobo1982@.gmail.com) writes:
Quote:
Originally Posted by
Quote:
Originally Posted by
>I learnt just the other day that ALTER ASSEMBLY is not in the repetoir
>of Visual Studio. I don't use Visual Studio to work with assemblies
>but stick to the command line. And all impression I get is that
>using Visual Studio just makes things harder.
>
It seems Microsoft hasn't done the job well, but if we have a lot of
objects in the assembly, the manual process of dropping and creating
them is horrible.
Yes, it's horrible if you have to do it each time you change the
implementation of some single method, and it's amazing that VS cannot
handle this situation.
If you change the interface, it's still a lot of work of course of dropping
and recreating objects. But it is or more less inevitable.
I don't know what's in your assemblies, but I woudl suggest that if you
have a suite of functions and procedures that are independent of each other,
that it's best to have a separate assembly for each function/procedure. Of
course, if they use a lot of common code, you still need to put that common
code in a single assembly in which case you are back to the same situation.
--
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
Sunday, February 12, 2012
ClickOnce for SQL Express Database?
I'm working on an app in Visual Studio 2005 that needs to have installed locally SQL Express to handle its own data.
This app is in a strong upgrading process. I've been using clickonce to publish the app and let my users upgrade automatically (by the way this works amazing ...).
Yet many times changes to the DB are made. Is there a simple way to upgrade their local SQL Express DB like click once does with the app?
Thanks.
hi,
I'm not sure about click once capability to perform the requested task, but even if possible, are you sure you like to do it? that means you would upgrade users database loosing their data modifications... I do think you've better just "upgrade" the database schema and not replace their database...
if this is the case, you can perhaps have a look at syncornization tools like http://www.red-gate.com/products/SQL_Compare/index.htm..
regards
|||Thanks, the products looks like a very good solution. I've already downloaded it and I'm testing.
Have you used it yourself? Do you know other products that do the same?
|||hi,
yes, I do use it myself since versions 2...
I know other similar tools are available out there, like http://www.innovartis.co.uk/database_dbghost_home.aspx, but I've always been satisfied by red-gate tools.. they even provides http://www.red-gate.com/products/SQL_Packager/index.htm, base on SQL Compare tool, to just distribute an exe packaged file that, at run time, will perform the metadata updates for you..
but here we are in advertising mode
BTW, I'm not involved in any way with the reported products/company, I'm just a user as you could be..
for further info, a free comparison tool is available at http://www.absistemi.it/sqlCompare.aspx by another italian SQL Server MVP fellow, but I'm not sure it has been updated for SQL Server 2005...
regards
|||Grazie tante ...|||prego...
(you're welcome)
Friday, February 10, 2012
Clearing the Error List window
Thanks,
Hans Geurtsen.Well... get rid of the errors in the code and rebuild the project