Showing posts with label deployment. Show all posts
Showing posts with label deployment. Show all posts

Sunday, March 25, 2012

Cant attach a database using MSDE deployment toolkit

I am using the MSDE deployment toolkit along with the
sample programs provided by Mario S. Almost everything is
fine when I want to create a database, add tables, and
etc. but I am unable to attach a database.
On one instance called "george" i have created a database
called "lawncare" and moved it to the C: drive. I am using
the same embedded resource file "DBInstall.sql" that is
used in the examples (and which works for creating tables,
etc) but I receive the following error message:
"An exception occured in the ONAfterInstall event handler
of DBInstaller.CustomInstaller.
>Line 2: Incorrect systax near 'go'
Line 4: Incorrect syntax near 'go'"
The script I am using in the resource file is:
set nocount off
go
exec sp_attach_single_file_db @.dbname = 'lawncare',
@.physname = 'c:\lawncare_Data.mdf'
go
If, in the same resource file I were to use this script:
CREATE TABLE [dbo].[City] (
[CityId] [int] IDENTITY (0, 1) NOT NULL ,
[Description] [varchar] (50) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
The table would be created just fine...(the routine
substitutes ";" for "go" when reading the text to execute.)
Any help would be appreciated.
Thanks
NJ
NJ,
Your sql is working fine, I tried it and it worked. But make sure that this database that you are trying to attach is actually detached from somewhere before. The sp_attach_single_file_db works with databases which are detached from somewhere. Also mak
e sure that your log file is at c:\ drive too .
let me know if it doesn't work.
dev

Thursday, March 8, 2012

Cannot use anonymous methods inside SQLCLR...

Hi all,

The problem is: when you're trying to call in method MyMethod anonymous method that doesn't use local variables, deployment of the assembly will fail referring that MyMethod tries to store smth. in the static variable. Indeed, looking at the compiled CLR code, you can see that anonymous delegate is cached in the private static delegate and the call looks like:

If(ClassName.privateStaticDelegate == null)
ClassName.privateStaticDelegate = new MyDelegate(HiddenMethodName);
CallAnonymousMethod(ClassName.privateStaticDelegate);

Is there any workaround to fix this problem.

P.S. I googled about this problem and found only one article on it:
http://www.ayende.com/Blog/default,date,2005-12-26.aspx

Hi Almaz,

I'm not quite sure I understand the question, but we're pretty picky about statics in SAFE and EXTERNAL ACCESS assemblies. They should be okay if they're readonly or const, but otherwise not.

Cheers,

-Isaac

|||

Hi Isaac,

Here is the repro: Create a new SQL Server Project, add a following stored procedure and try to deploy the assembly:

using System;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[SqlProcedure]
public static void StoredProcedure1()
{
int[] myIntArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int i = Array.FindIndex(myIntArray, delegate (int value)
{
return value == 5;
});
}
}

Following variant works:

using System;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[SqlProcedure]
public static void StoredProcedure1()
{
int[] myIntArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int valueToFind = 5;
int i = Array.FindIndex(myIntArray, delegate (int value)
{
return value == valueToFind;
});
}
}

Thanks in advance,
Sergei Almazov

|||

Right, the problem is that we don't allow store into a static field. In this case, the store was an optimization by the C# compiler. We have a requirement that whenever compiler does this, it should mark the static field with [System.Runtime.CompilerServices.CompilerGenerated] attribute. Apparently, this didn't happen here.

There are two possible workarounds here:

1) mark the class with [System.Runtime.CompilerServices.CompilerGenerated] attribute

2) register the assembly as UNSAFE assembly.

We will follow up with C# compiler and fix the issue, so you can remove your workaround in the future.

-Xiaowei

Cannot use anonymous methods inside SQLCLR...

Hi all,

The problem is: when you're trying to call in method MyMethod anonymous method that doesn't use local variables, deployment of the assembly will fail referring that MyMethod tries to store smth. in the static variable. Indeed, looking at the compiled CLR code, you can see that anonymous delegate is cached in the private static delegate and the call looks like:

If(ClassName.privateStaticDelegate ==null)
ClassName.privateStaticDelegate =new MyDelegate(HiddenMethodName);
CallAnonymousMethod(ClassName.privateStaticDelegate);

Is there any workaround to fix this problem.

P.S. I googled about this problem and found only one article on it:
http://www.ayende.com/Blog/default,date,2005-12-26.aspx

Hi Almaz,

I'm not quite sure I understand the question, but we're pretty picky about statics in SAFE and EXTERNAL ACCESS assemblies. They should be okay if they're readonly or const, but otherwise not.

Cheers,

-Isaac

|||

Hi Isaac,

Here is the repro: Create a new SQL Server Project, add a following stored procedure and try to deploy the assembly:

using System;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[SqlProcedure]
public static void StoredProcedure1()
{
int[] myIntArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int i = Array.FindIndex(myIntArray, delegate (int value)
{
return value == 5;
});
}
}

Following variant works:

using System;
using Microsoft.SqlServer.Server;
public partial class StoredProcedures
{
[SqlProcedure]
public static void StoredProcedure1()
{
int[] myIntArray = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int valueToFind = 5;
int i = Array.FindIndex(myIntArray, delegate (int value)
{
return value == valueToFind;
});
}
}

Thanks in advance,
Sergei Almazov

|||

Right, the problem is that we don't allow store into a static field. In this case, the store was an optimization by the C# compiler. We have a requirement that whenever compiler does this, it should mark the static field with [System.Runtime.CompilerServices.CompilerGenerated] attribute. Apparently, this didn't happen here.

There are two possible workarounds here:

1) mark the class with [System.Runtime.CompilerServices.CompilerGenerated] attribute

2) register the assembly as UNSAFE assembly.

We will follow up with C# compiler and fix the issue, so you can remove your workaround in the future.

-Xiaowei