Solved

Calling a method from sql server 2008: method static

Posted on 2011-03-04
6
269 Views
Last Modified: 2012-08-13
This method 'GetStringFromNumber' is made of. net and I will use my database sql server 2008

 When I declare as follows
 public string GetNumberString (double value)
 displays the following message
 ConvertirNumerosALetra Procedure, Line 1Method, property or the 'GetStringFromNumber'class 'ConvertNumberToText.Utilities' from assembly 'ConvertNumberToText'is not static

 So the solution is
 public static string GetNumberString (double value)

 I want to know why?
0
Comment
Question by:enrique_aeo
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 35040097
Can you provide an example of how you are calling it?
0
 

Author Comment

by:enrique_aeo
ID: 35040203
select dbo.DecimalToString(19.98)
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 100 total points
ID: 35083132
the "why" is because you (sql server, actually) need(s) to be able to call the method without needing to initiating an object from the class that holds the method.
it's a "by design" issue.
0
 
LVL 28

Accepted Solution

by:
Ryan McCauley earned 150 total points
ID: 35083375
The reason for this behavior is that SQL Server doesn't instantiate the class - it just calls into the code. Since nothing is persisted, there's no way to keep a class reference, so the code needs to be static to ensure that. In your case, the method likely acts only on it's parameters, not relying on any state external to itself, so you're fine to just slap a "static" on there without much thought. It's when you're interacting with other objects in your class or others that are shared that you can run into problems with a poorly planned "static" modifier.

Also, since SQL Server is naturally multi-threaded, it need to ensure that multiple threads can call the method at a time without stepping on each other. When you declare the method static, (to me at least) it means you've thought about the implications of that and that you've built your class appropriately, not using any globals, but keeping all the variables internal to your method, where they're safe for multi-threading.

When you think about the context in which SQL Server is consuming your method, it makes sense, but it confused me at first as well.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

747 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

12 Experts available now in Live!

Get 1:1 Help Now