Solved

sql server 2008 register dll

Posted on 2010-08-23
5
543 Views
Last Modified: 2012-06-27
hi experts, i have this code
namespace ConvertNumberToText
{
    public class Utilities
    {
        public string GetStringFromNumber(double value)
        {
            Dictionary<double, string> map = new Dictionary<double, string>()
    {
        {  0F, "CERO" },
        {  1F, "UNO" },
.....

i am trying to register the dll in database

sp_configure 'clr enabled', 1
reconfigure
go

create assembly [Amag.ConvertNumberToText]
from 'C:\Certifica\ConvertNumberToText.dll'

create function ConvertirNumerosALetra (@nota decimal(2,2)) returns nvarchar(500)
external name [Amag.ConvertNumberToText].[ConvertNumberToText.Utilities].GetStringFromNumber;
 
I need to register this dll in the database, but I get the following error:Mens 6573, Level 16, State 1, Procedure ConvertirNumerosALetra, Line 1Method, property or the 'GetStringFromNumber' class 'ConvertNumberToText.Utilities' from assembly 'ConvertNumberToText' is not static.
0
Comment
Question by:enrique_aeo
  • 3
5 Comments
 
LVL 3

Expert Comment

by:shawnmstout
ID: 33506048
i believe this tutorial is what your searching for

http://msdn.microsoft.com/en-us/library/ms164653.aspx
0
 

Author Comment

by:enrique_aeo
ID: 33506067
if I read that article but did not resolve my problem, I would like assistance with the code that I copied
0
 

Author Comment

by:enrique_aeo
ID: 33506340
i attached my code
Nuevo-documento-de-texto.txt
0
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 33507645
As the error message says you are missing the "static" modifier on your message. Remember that you are building a set of utility functions which are typically public static.

i.e., you want to call this as ConvertNumberToText.Utilities.GetStringFromNumber(0.0)

So very simple fix to your code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConvertNumberToText
{
   public class Utilities
   {
      
      public static string GetStringFromNumber(double value)
      {
         Dictionary<double, string> map = new Dictionary<double, string>()
   {
      {  0F, "CERO" },
      {  1F, "UNO" },
      {  2F, "DOS" },
      {  3F, "TRES" },
      {  4F, "CUATRO" },
      {  5F, "CINCO" },
      {  6F, "SEIS" },
      {  7F, "SIETE" },
      {  8F, "OCHO" },
      {  9F, "NUEVE" },
      { 10F, "DIEZ" },
      { 11F, "ONCE" },
      { 12F, "DOCE" },
      { 13F, "TRECE" },
      { 14F, "CATORCE" },
      { 15F, "QUINCE" },
      { 16F, "DIECISEIS" },
      { 17F, "DIECISIETE" },
      { 18F, "DIECIOCHO" },
      { 19F, "DIECINUEVE" },
      { 20F, "VEINTE" },
      { 30F, "TREINTA" },
      { 40F, "CUARENTA" },
      { 50F, "CINCUENTA" },
      { 60F, "SESENTA" },
      { 70F, "SETENTA" },
      { 80F, "OCHENTA" },
      { 90F, "NOVENTA" },
   };

         double whole = Math.Truncate(value);
         double fraction = Math.Round((value - whole), 2);
         StringBuilder result = new StringBuilder();

         if (!map.Keys.Contains(whole))
         {
            double ones = whole % 10;
            double tens = Math.Truncate((whole / 10) % 10) * 10;

            result.Append(map[tens] + " y " + map[ones]);
         }
         else
         {
            result.Append(map[whole]);
         }

         if (fraction != 0D)
         {
            result.Append(" PUNTO ");

            fraction = Math.Round(fraction * 100);

            if (!map.Keys.Contains(fraction))
            {
               double hundredths = fraction % 10;
               double tenths = Math.Truncate((fraction / 10) % 10) * 10;

               result.Append(map[tenths] + " y " + map[hundredths]);
            }
            else
            {
               if (fraction < 10D)
               {
                  result.Append(map[0] + " " + map[fraction]);
               }
               else
               {
                  result.Append(map[fraction]);
               }
            }
         }

         return result.ToString();
      }
   }
}

Open in new window

0
 

Author Comment

by:enrique_aeo
ID: 33512036
OK MY FRIEND,
that problem is already solved. Thanks
Now I have this otherError in CREATE FUNCTION for "ConvertirNumerosALetra" because the types T-SQL and CLR parameter "@ note" do not match.

create function ConvertirNumerosALetra (@nota decimal(2,2)) returns nvarchar(500)
external name [Amag.ConvertNumberToText].[ConvertNumberToText.Utilities].GetStringFromNumber;
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question