Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Friday, March 30, 2012

Managed C++ User-defined Aggregate Function

Hi all,

I'm attempting to write an aggregate function in C++ to compare performance with the equivalent function in C#.

However, I'm having problems getting SQL Server to see the function in the assembly. It allows me to load the assembly into the database, but I can't see the type in it.

Here's my code:

// CPPTest.h

#pragma once

using namespace System;
using namespace Microsoft::SqlServer::Server;
using namespace System::Data::SqlTypes;
using namespace System::Data::SqlClient;

namespace CPPTest {

[Serializable]
[Microsoft::SqlServer::Server::SqlUserDefinedAggregate(
Format::Native,
Name="AGG_CPP_OR")]
public ref struct AGG_CPP_OR
{
public:
void Init();
void Accumulate(SqlInt32 Value);
void Merge(AGG_CPP_OR^ Group);
SqlInt32 Terminate();

private:
SqlInt32 m_accum;
};

}

// CPPTest.cpp

#include "stdafx.h"

#include "CPPTest.h"

void CPPTest::AGG_CPP_OR::Init()
{
m_accum = 0;
}

void CPPTest::AGG_CPP_OR::Accumulate(SqlInt32 Value)
{
m_accum = m_accum | Value;
}

void CPPTest::AGG_CPP_OR::Merge(CPPTest::AGG_CPP_OR^ Group)
{
m_accum = m_accum | Group->m_accum;
}

SqlInt32 CPPTest::AGG_CPP_OR::Terminate()
{
return m_accum;
}

Compile it with /clr:safe option and it can be loaded as an assembly into SQL Server 2005 (9.0.1399), but the AGG_CPP_OR type is not seen as an aggregate function. I've also tried implementing IBinarySerialize and setting Format to Format::UserDefined (and putting in MaxByteSize) but it makes no difference.

Does anyone know what I'm missing here?

Many thanks,OK, take it out of the CPPTest namespace and it can be added as an aggregate function with

CREATE AGGREGATE BITWISE_OR(@.input int)
RETURNS int
EXTERNAL NAME [CPPTest].[AGG_CPP_OR];
GO

Now it's a dependancy issue stopping it from running, but I'll keep on it.

Thanks,

Wednesday, March 21, 2012

Making "Server Management Studio" read only ?

Hi - I would like to be able to setup "Server Management Studio" so
that no changes can be made to the database/schemas (we write scripts
to make changes we want).
What's the best way to do this ?
Just to explain why - I want developers to be able to browse table
definitions etc but I want to ensure that no changes ever take place by
accident when doing so.
Thanks
Richard.Create a login which has only read only permissions. Take a look at
db_datareader fixed database role. The user should no be a member of
sysadmin server role
<shearichard@.gmail.com> wrote in message
news:1168142809.101663.284960@.i15g2000cwa.googlegroups.com...
> Hi - I would like to be able to setup "Server Management Studio" so
> that no changes can be made to the database/schemas (we write scripts
> to make changes we want).
> What's the best way to do this ?
> Just to explain why - I want developers to be able to browse table
> definitions etc but I want to ensure that no changes ever take place by
> accident when doing so.
> Thanks
> Richard.
>|||Uri Dimant wrote:
> Create a login which has only read only permissions. Take a look at
> db_datareader fixed database role. The user should no be a member of
> sysadmin server role
>
OK thanks I will try that. Reading the doco for db_datareader mentions
being able to read data but doesn't mention whether a db_datareader
will be able to read table definitions etc - maybe that's a given ?
Anyway thanks and I will try what you suggest.
regards
Richard.
> <shearichard@.gmail.com> wrote in message
> news:1168142809.101663.284960@.i15g2000cwa.googlegroups.com...
> > Hi - I would like to be able to setup "Server Management Studio" so
> > that no changes can be made to the database/schemas (we write scripts
> > to make changes we want).
> >
> > What's the best way to do this ?
> >
> > Just to explain why - I want developers to be able to browse table
> > definitions etc but I want to ensure that no changes ever take place by
> > accident when doing so.
> >
> > Thanks
> >
> > Richard.
> >|||<shearichard@.gmail.com> wrote in message
news:1168296784.941138.131700@.42g2000cwt.googlegroups.com...
> Uri Dimant wrote:
>> Create a login which has only read only permissions. Take a look at
>> db_datareader fixed database role. The user should no be a member of
>> sysadmin server role
> OK thanks I will try that. Reading the doco for db_datareader mentions
> being able to read data but doesn't mention whether a db_datareader
> will be able to read table definitions etc - maybe that's a given ?
> Anyway thanks and I will try what you suggest.
I believe they can.
> regards
>
> Richard.
>
>> <shearichard@.gmail.com> wrote in message
>> news:1168142809.101663.284960@.i15g2000cwa.googlegroups.com...
>> > Hi - I would like to be able to setup "Server Management Studio" so
>> > that no changes can be made to the database/schemas (we write scripts
>> > to make changes we want).
>> >
>> > What's the best way to do this ?
>> >
>> > Just to explain why - I want developers to be able to browse table
>> > definitions etc but I want to ensure that no changes ever take place by
>> > accident when doing so.
>> >
>> > Thanks
>> >
>> > Richard.
>> >
>

Making "Server Management Studio" read only ?

Hi - I would like to be able to setup "Server Management Studio" so
that no changes can be made to the database/schemas (we write scripts
to make changes we want).
What's the best way to do this ?
Just to explain why - I want developers to be able to browse table
definitions etc but I want to ensure that no changes ever take place by
accident when doing so.
Thanks
Richard.
Create a login which has only read only permissions. Take a look at
db_datareader fixed database role. The user should no be a member of
sysadmin server role
<shearichard@.gmail.com> wrote in message
news:1168142809.101663.284960@.i15g2000cwa.googlegr oups.com...
> Hi - I would like to be able to setup "Server Management Studio" so
> that no changes can be made to the database/schemas (we write scripts
> to make changes we want).
> What's the best way to do this ?
> Just to explain why - I want developers to be able to browse table
> definitions etc but I want to ensure that no changes ever take place by
> accident when doing so.
> Thanks
> Richard.
>
|||Uri Dimant wrote:
> Create a login which has only read only permissions. Take a look at
> db_datareader fixed database role. The user should no be a member of
> sysadmin server role
>
OK thanks I will try that. Reading the doco for db_datareader mentions
being able to read data but doesn't mention whether a db_datareader
will be able to read table definitions etc - maybe that's a given ?
Anyway thanks and I will try what you suggest.
regards
Richard.
[vbcol=seagreen]
> <shearichard@.gmail.com> wrote in message
> news:1168142809.101663.284960@.i15g2000cwa.googlegr oups.com...
|||<shearichard@.gmail.com> wrote in message
news:1168296784.941138.131700@.42g2000cwt.googlegro ups.com...
> Uri Dimant wrote:
> OK thanks I will try that. Reading the doco for db_datareader mentions
> being able to read data but doesn't mention whether a db_datareader
> will be able to read table definitions etc - maybe that's a given ?
> Anyway thanks and I will try what you suggest.
I believe they can.

> regards
>
> Richard.
>
>

Making "Server Management Studio" read only ?

Hi - I would like to be able to setup "Server Management Studio" so
that no changes can be made to the database/schemas (we write scripts
to make changes we want).
What's the best way to do this ?
Just to explain why - I want developers to be able to browse table
definitions etc but I want to ensure that no changes ever take place by
accident when doing so.
Thanks
Richard.Create a login which has only read only permissions. Take a look at
db_datareader fixed database role. The user should no be a member of
sysadmin server role
<shearichard@.gmail.com> wrote in message
news:1168142809.101663.284960@.i15g2000cwa.googlegroups.com...
> Hi - I would like to be able to setup "Server Management Studio" so
> that no changes can be made to the database/schemas (we write scripts
> to make changes we want).
> What's the best way to do this ?
> Just to explain why - I want developers to be able to browse table
> definitions etc but I want to ensure that no changes ever take place by
> accident when doing so.
> Thanks
> Richard.
>|||Uri Dimant wrote:
> Create a login which has only read only permissions. Take a look at
> db_datareader fixed database role. The user should no be a member of
> sysadmin server role
>
OK thanks I will try that. Reading the doco for db_datareader mentions
being able to read data but doesn't mention whether a db_datareader
will be able to read table definitions etc - maybe that's a given ?
Anyway thanks and I will try what you suggest.
regards
Richard.
[vbcol=seagreen]
> <shearichard@.gmail.com> wrote in message
> news:1168142809.101663.284960@.i15g2000cwa.googlegroups.com...|||<shearichard@.gmail.com> wrote in message
news:1168296784.941138.131700@.42g2000cwt.googlegroups.com...
> Uri Dimant wrote:
> OK thanks I will try that. Reading the doco for db_datareader mentions
> being able to read data but doesn't mention whether a db_datareader
> will be able to read table definitions etc - maybe that's a given ?
> Anyway thanks and I will try what you suggest.
I believe they can.

> regards
>
> Richard.
>
>