Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling a method from sql server 2008: method static

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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

721 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