Solved

Calling a method from sql server 2008: method static

Posted on 2011-03-04
6
273 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
[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
6 Comments
 
LVL 75

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 143

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

615 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