Solved

sql server 2008 register dll

Posted on 2010-08-23
5
540 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now