Solved

sql server 2008 register dll

Posted on 2010-08-23
5
548 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 60

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
too many installs coming along with SQL 2016? 1 34
Substring works but need to tweak it 14 35
Using this function 4 53
Assigning Database Principals to Database Roles 3 39
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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