Showing posts with label defined. Show all posts
Showing posts with label defined. Show all posts

Monday, March 19, 2012

Email From a CLR Stored Proc - SMTPPermission

I am trying to send email from a CLR Stored proc.

I get the following error.

A .NET Framework error occurred during execution of user defined routine or aggregate 'HelloWorld':
System.Security.SecurityException:

Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.Net.Mail.SmtpClient.Initialize()
at System.Net.Mail.SmtpClient..ctor(String host)
at StoredProcedures.HelloWorld()
.

How do I handle the SmtpPermission?

Here is the stored proc

public static void HelloWorld()
{
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress("test@.test.EDU");
mail.To.Add("test@.test.EDU");

//set the content
mail.Subject = "Hello World";
mail.Body = "Did you get this? I am emailing from a CLR stored proc!";

//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);

}

SQL Server comes with when last I counted three different mail internal so you are reinventing the wheel by using System.Net. Run a search for SQL Server mail and SQL Server Agent mail in the BOL (books online) because I think there are known issues with the IMAPI mail. SQL Server Agent mail can also be used to send pages. Hope this helps.|||

Have the same problen - and the above RUDE comment isnt any help!

Instantiating SmtpClient gives -exception of type 'System.Security.SecurityException'

Hmmm - if it would work we've got a lot of objects we could put to work without reenventing new methods just to work in a CLR proc!

What's necessary to get SmtpClient to work in a CLR proc?

|||

OK - there's 2 or 3 ways to get the job done...

Easiest( although not MSDN recommended just to jet a CLR proc to run) is to set the permission level to External_Access...

SQL Server Host Policy Level Permission Sets
The set of code access security permissions granted to assemblies by the SQL Server host policy level is determined by the permission set specified when creating the assembly. There are three permission sets:SAFE,EXTERNAL_ACCESS andUNSAFE.

The permision level is set on the properties pages of the CLR project , database tab - set Permission Level-External, set Aassembly Owner-dbo, and run tsql 'ALTERDATABASE DataBaseName SET TRUSTWORTHYON'
This will get the job DONE! - and the SmtpClient wiill work ok...

Then do it right and Sign the Assenbly with a Strong name Key file...
Read MSDN

Creating an Assembly

Discusses creating SAFE, EXTERNAL_ACCESS, and UNSAFE CLR assemblies in SQL Server

That's it...

RLewis - MCSD

(and there sure is a lot of NO HELP answers goin around...)

|||

Brilliant!!!!!

Solution 2 worked like a charm. El mucho gracias!!!!

Party!!!

Sunday, February 26, 2012

eliminate the Return charactor in a column

Hi,
We have a column defined as ntext for a column and we need to transfer this
column to oralce platform. Before transferring, we convert the data to
varchar. Some of data content "RETURN" charactor, and it caused issue for
providing report or printing.
Please suggest a way to eliminate the "RETURN" charactor in this column and
we can keep all the data in the nice order. Thanks.
Best Regards,
Lynnhttp://www.aspfaq.com/2445
"Lynn" <Lynn@.discussions.microsoft.com> wrote in message
news:3F6073C5-BF70-4DFA-BAE0-DD4EFA30A8AA@.microsoft.com...
> Hi,
> We have a column defined as ntext for a column and we need to transfer
> this
> column to oralce platform. Before transferring, we convert the data to
> varchar. Some of data content "RETURN" charactor, and it caused issue for
> providing report or printing.
> Please suggest a way to eliminate the "RETURN" charactor in this column
> and
> we can keep all the data in the nice order. Thanks.
> --
> Best Regards,
> Lynn

Sunday, February 19, 2012

Either a connection cannot be made to the .\sql2005 server, or Analysis Services is not running

I get this error when trying to deploy a Analysis Services Project. I don't have the cube defined yet. I did have sql 2000 and sql 2005 installed on the same machine at one point, but I've since uninstalled them both and reinstalled only sql 2005.

Error 1 Errors in the OLE DB provider. Could not connect to the redirector. Ensure that the SQLBrowser service is running on the '.' server. Errors in the OLE DB provider. An error occurred while named instance information was being retrieved from the SQLBrowser service on the '.' server. Either a connection cannot be made to the .\sql2005 server, or Analysis Services is not running on the computer specified. Errors in the metadata manager. An error occurred when loading the Tbl PM Project dimension, from the file, '\\?\C:\Program Files\Microsoft SQL Server\MSSQL.3\OLAP\Data\mbn_gargle.0.db\Tbl PM Project.4.dim.xml'. File system error: The following error occurred while writing to the file 'MSSQLServerOLAPService': The event log file is full. . Errors in the metadata manager. An error occurred when loading the MBN Gargle cube, from the file, '\\?\C:\Program Files\Microsoft SQL Server\MSSQL.3\OLAP\Data\mbn_gargle.0.db\MBN Gargle.15.cub.xml'. File system error: The following error occurred while writing to the file 'MSSQLServerOLAPService': The event log file is full. . 0 0

The problem is actually because it is trying to access a named instance ".\sql2005", which no longer exists. I can see that from this message,

"Either a connection cannot be made to the .\sql2005 server, or Analysis Services is not running on the computer specified."

This happens on brand new projects.

I saw other threads on this subject and the resolutions didn't work. I tried installing the msi file listed on the sql server 2005 packages install (listed on another thread, sorry I don't have the file name handy) but it didn't work.

How do I get around this bug and have SQL look at the only sql instance on the machine, the localhost? The browser service is turned on.

Bob

Check your BI Dev studio project settings. Looks like your project is still trying to deploy to the .\sql2005 instance.

Right click on your project node select "Properties". Click on the "Deployment" node on the left and see what is the value for the Server property. Change it to the "localhost".

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

Friday, February 17, 2012

Effective Date selection in SQL

Problem: Selecting the most appropriate row based upon the row's effective date (a user defined field of the row) verses the current date and time.

Platform: Microsoft SQL Server 2000

Details:
In a table of products, each record is a product, or a version of a product. These products or versions of products are "Effective Dated", meaning, a row is activated by the date it becomes effective by (do not be confused by an active row, and an active product - active row is the currently effective row, an active product is a flag set by the user as to define whether the product is active when it's effective date is reached). Example:

Product 1 (version 1)
Effective Date: 6/1/2003 12:00:00 AM
Price: $30
Status: Active

Product 1 (version 2)
Effective Date: 7/11/2003 12:00:00 AM
Price: $20
Status: Active

Product 1 (version 3)
Effective Date: 12/25/2003 12:00:00 AM
Price: $15
Status: Active

Product 1 (version 4)
Effective Date: 1/1/2004 12:00:00 AM
Status: Inactive

In the above case, this SINGLE product has four records in the product table representing different versions. Product 1 version 1 has expired since Product 1 version 2 is effective today (7/11). Product 1 version 3 and version 4, however, have not come about yet due to their effective dating in the future. Product versions 1 through 3 are all active, and the product is no longer available after 1/1/2004, when version 4 becomes effective and the status changes to "Inactive".

The problem I'm experiencing with my SQL is that I cannot differentiate between the version effective currently and the future versions.

My current SQL looks as such:

SELECT sProdName
FROM tblProducts
WHERE NOT EXISTS
(
SELECT P.cProdCode, P.dtEffDate
FROM tblProducts AS P
WHERE
tblProducts.cProdCode = P.cProdCode AND
tblProducts.dtEffDate < P.dtEffDate
)
AND bActive = 1
AND cProdCode = 'somecode'
ORDER BY sProdName

In the above SQL, bActive is a flag that declares this product as an active product (verses inactive) and cProdCode is a code that all versions of the Product share. Ex:

iID: 1
sProdName: Product 1
cProdcode: PROD1
bActive: 1
dtEffDate: 6/1/2003 12:00:00 AM

iID: 2
sProdName: Product 1
cProdcode: PROD1
bActive: 1
dtEffDate: 7/11/2003 12:00:00 AM

iID: 3
sProdName: Product 1
cProdCode: PROD1
bActive: 0
dtEffDate: 1/1/2004 12:00:00 AM

The above SQL is effective in ignoring the expired versions of the product, but returns the current and future versions. I've attempted to massage the SQL to ignore the expired and future versions (leaving me with the single, currently active, version).

Ideally, I'd like to do this without having to create flags for the records that deam them as past, present, future, or having to export versions out into an archive table. This should be able to be determined by strictly SQL, but haven't been able to get the data to return as I'd like it..

In the end, the final result would be a single record of the version of the product which is currently effective, and alertnately, the ability to retrieve a set of records listing all of the currently effective active products.

Any ideas?Now, I should mention that I have a version of this SQL that works, but I suppose my ultimate question is "Is this the most efficient and proper way to do this or is there a better way?"

Here is the SQL that does work, but it nags at me with the use of TOP and ORDER BY. It doesn't seem as though this is the proper elegant solution:

SELECT TOP 1 *
FROM tblProducts AS P
WHERE
P.iProdID IN
(
SELECT iProdID
FROM tblProducts P2
WHERE
P2.dtEffDate < GETDATE()
)
AND P.bActive = 1
AND P.cProdCode = 'somecode'
ORDER BY P.dtEffDAte DESC

If I do not use TOP, it returns every version of a product except the future versions. If I do not use ORDER BY it returns them in an order inconsistant with their effective date. So combined together, the records are sorted most current->least current, then chopped at the top for the most current effective dated product.

Now, this comes into play heavily when we start talking about retrieving the most recent version of all of the products. Sure the above works when getting the most current version of a single product, but (due to the "TOP") does not work properly when attempting to retrieve the most current version of all active products. The above SQL's "TOP" directive is in there to drop off the expired version of the product, and in this case, TOP drops off more then just expired versions of products.. it drops everything except the lucky record at the top of the set.|||i really don't understand your various definitions of active, inactive, flags, effective dates, etc.

your design sounds fairly complicated

however, i did pick up on one thing

you said your sql works, but only for one product at a time, and "does not work properly when attempting to retrieve the most current version of all active products"

okay, i think i can translate your sql so it will work for all products:
select *
from tblProducts AS P
where dtEffDate =
( select max(dtEffDate)
from tblProducts
where cProdCode = P.cProdCode
and dtEffDate < GETDATE()
and bActive = 1
)
and bActive = 1 this is a correlated subquery so it picks the highest date in each group, where the group is defined as all product rows with the same cProdCode (the P inside the subquery is the correlation variable)

let me know if it works

rudy
http://r937.com/|||Hi Rudy,

I apologize for the complexity of the project, but I think you nailed the solution. I've done some cursory testing, and just looking over the SQL, it looks right on. Tonight I'll take some time to do some more testing, but it looks good. I hadn't even thought of using the MAX function. Thanks for your assistance, I appreciate you taking the time to go through all my details (even if they were a bit long and confusing) and coming up with a solid solution.|||It looks good.. I've done some more thorough testing and it seems to work well. Thanks again!|||It looks good.. I've done some more thorough testing and it seems to work well. Thanks again!

Wednesday, February 15, 2012

Edition vs Engine Edition

Serverproperty has two parameters that seem closely defined:
"Engine Edition" and "Edition". What is the difference between them? Is
there any detailed documentation on the difference, and the consequences
therefrom?
I have a server where Edition="Developer Edition", and EngineEdition = Enterprise.
--
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)Think of the Edition as the license you pay for and the Engine Edition to be
the functionality you get. In your case, you get Enterprise Edition
functionality for the low price of a Developer Edition.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
"Blue Sky" <BlueSky@.discussions.microsoft.com> wrote in message
news:682722BB-5AC1-4565-8EB8-F573340ED2BE@.microsoft.com...
Serverproperty has two parameters that seem closely defined:
"Engine Edition" and "Edition". What is the difference between them? Is
there any detailed documentation on the difference, and the consequences
therefrom?
I have a server where Edition="Developer Edition", and EngineEdition =Enterprise.
--
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)

Edition vs Engine Edition

Serverproperty has two parameters that seem closely defined:
"Engine Edition" and "Edition". What is the difference between them? Is
there any detailed documentation on the difference, and the consequences
therefrom?
I have a server where Edition="Developer Edition", and EngineEdition =
Enterprise.
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)
Think of the Edition as the license you pay for and the Engine Edition to be
the functionality you get. In your case, you get Enterprise Edition
functionality for the low price of a Developer Edition.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
"Blue Sky" <BlueSky@.discussions.microsoft.com> wrote in message
news:682722BB-5AC1-4565-8EB8-F573340ED2BE@.microsoft.com...
Serverproperty has two parameters that seem closely defined:
"Engine Edition" and "Edition". What is the difference between them? Is
there any detailed documentation on the difference, and the consequences
therefrom?
I have a server where Edition="Developer Edition", and EngineEdition =
Enterprise.
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)

Edition vs Engine Edition

Serverproperty has two parameters that seem closely defined:
"Engine Edition" and "Edition". What is the difference between them? Is
there any detailed documentation on the difference, and the consequences
therefrom?
I have a server where Edition="Developer Edition", and EngineEdition =
Enterprise.
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)Think of the Edition as the license you pay for and the Engine Edition to be
the functionality you get. In your case, you get Enterprise Edition
functionality for the low price of a Developer Edition.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau
"Blue Sky" <BlueSky@.discussions.microsoft.com> wrote in message
news:682722BB-5AC1-4565-8EB8-F573340ED2BE@.microsoft.com...
Serverproperty has two parameters that seem closely defined:
"Engine Edition" and "Edition". What is the difference between them? Is
there any detailed documentation on the difference, and the consequences
therefrom?
I have a server where Edition="Developer Edition", and EngineEdition =
Enterprise.
The Spirit gives life; the flesh counts for nothing! (Jn 6:63)

Editing User Defined Data type

Is there an easy way to edit an existing User Defined Data type ? For instance i have a custom data type address of base type nvarchar with a length of 40, I want to increase this custom data types length to 50, is there a way to do it or is it even supported?

The SQL Server 2005 Mangement Studio does not allow you do it..is there a work around for this?

Thanks,

Krishna

There is no easy way to do this without dropping and recreating the user-defined data type. You can do this via TSQL. I do not know about the GUI. You might want to ask this question in the SQL Server Tools forum.|||

Thanks, its the same with GUI, its not editable, it just allows us to either delete them and re-create them. Also before deleting them it makes us to remove all references, so its a bit of work..

Regards,

Krishna