Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calling a method from sql server 2008: method static

Posted on 2011-03-04
6
Medium Priority
?
278 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 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 400 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 600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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…
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.

971 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