Sql Server - Access A Shared Function From An Instance Of An Object?

Dec 28, 2010

The context of this question is that I am trying to debug performance issues (apart from the obvious ones I already know about and can find).I inherited a code base (VB.NET) for an ASP.NET app. This is an app that was developed way back in .NET 1.1 days, and was the first .NET app for a lot of the developers who worked on it.

In this code base is a class called DatabaseUtility that contains several Shared Public methods as well as non-Shared Public Functions and Subs for CRUD operations to the database (SQL Server).

It is common in my "BL" that a method creates an instance of the DatabaseUtility which essentially figures out what the connection string should be and opens a connection, as well as giving the developer a handle to the other methods contained within it.Dim utility as New DatabaseUtility()

Once I have that, I start to create parameters that I am going to pass to one of the methods in DatabaseUtility (like GetDataSet). There is a Shared method in my DatabaseUtility called CreateParameter which does essentially that. It creates a SqlParameter object so I can add it to a Parameters collection.

Now, the code base is littered with a lot of this:

utility.CreateParameter(...)However, because CreateParameter is a Shared method, I am not sure what is going on behind the scenes. I know because it is a Shared member that an instance of the DatabaseUtility is not created when I call it like this:DatabaseUtility.CreateParameter(...)

However, because I am calling it from an instance (utility), does that change the behavior at all?

View 1 Replies


ADVERTISEMENT

Creating A Shared Instance Of An Object?

Feb 13, 2012

I would like to create a global instance of a User Class that can be referenced by all the forms in my MDI application.This object may be set during the login procedure by the Login form but the user attributes are to be available for other forms. For example, MyUser.ID will be required for meeting the audit requirements whenever data is changed.

View 14 Replies

Access Of Shared Member Through Instance

Nov 6, 2009

After I formatted my laptop and reinstalled Visual Studio 2005, I receive a lot of same error as below message.
"Access of shared member through an instance; qualifying expression will not be evaluated"
If I click the error, it direct me to the line and all 102 error suggest me to add "Windows.Forms." before "DialogResult.OK". Should I add something on "Reference"?

View 4 Replies

C# - Access A Shared/static Member Through An Instance Variable?

Mar 3, 2011

Here's an example of what I'm talking about...

Public Class Sample1

Public Shared Function MyValue() As Integer
Return 0
End Function
Public Sub Code()

[Code]...

Me.MyValue gives a warning in VB.NET and (the equivalent code gives) an error in C#. Is there a particular reason for this? I find it more intuitive/natural to access the shared function using 'Me.MyValue' - but I avoid it to keep my warnings at 0. Did someone else just decide 'Nah, it makes more sense to do it the other way' or is there some technical reason I don't understand?

EDIT: I was thinking of it wrong, more like a 'sub class' in OOP. Even if something is declared in the base class, you access it through the instance you have. But that relationship is not the same with shared or static.

View 6 Replies

Object Reference Not Set To An Instance Of An Object When Calling A Function

Jun 13, 2012

I call the function GetDataTable and when it gets to the return line, I get the error message: Object reference not set to an instance of an object.

Dim DB As New DBConn
Dim gd As New DataAccess.GetData
Dim DT As New DataTable

[Code].....

Updated. I'll see if I can update with the DataAccess.GetData code. I didn't originally put it in there because our shop use it all the time and have no issues with it.

View 1 Replies

Event Handler Code Cause A Object Reference Not Set To An Instance Of An Object. Error (only Present On Live Server, Ok On Dev)?

Mar 4, 2010

Here is the code for the button click event;

Protected Sub CompetenciesButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CompetenciesButton.Click
Dim con As String = WebConfigurationManager.ConnectionStrings("foo").ToString()

[code].....

View 1 Replies

Failure To Create Data Controls To Access Database Object Reference Not Set To An Instance Of An Object?

May 3, 2011

I was create Access database with Access 2003. I create VB project with Visual Studio 2005 Standard With connection wizzard I create coonect with this Access database, select all tablesI see this database inside Data sources and inside Server explorer Test connection is OK When I drag and drop table from Data sources, Wizzard don't create DataGridView, DataSourceBinding etc .. and I see popup window with mesage: Object reference not set to an instance of an object and then "game over"

View 2 Replies

Shared - Understanding Access Modifiers In .Net With List ( Of Object)?

Mar 29, 2011

I've recently been updating a lot of my code to comply with proper n-tier architecture and OO programming, following examples from a book.I'm starting to get problems now because I don't fully understand the access modifiers.If I run the following code I get an error at the line

Dim clientFamilyDataAccessLayer As New ClientFamilyDAO

in the BLL at the point it creates an instance of the DAL. The full error message is: "The type initializer for 'ClientFamilyDAO' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object."

How do I use these function to create a list of ClientFamily objects that I can then work with?On my UI layer I'm creating a list of objects; ClientFamilies

Dim listOfClientFamilies As List(Of ClientFamily) = ClientFamily.GetClientFamiliesByKRM(selectedEmployee.StaffNumber)

This is the function in the BLL

Public Shared Function GetClientFamiliesByKRM(ByVal krmStaffNumber As Integer) As List(Of ClientFamily)
Dim clientFamilyDataAccessLayer As New ClientFamilyDAO
Return clientFamilyDataAccessLayer.GetClientFamiliesByKRM(krmStaffNumber)
End Function

and this is function in the DAL

Public Function GetClientFamiliesByKRM(ByVal staffNumber As Integer) As List(Of ClientFamily)
Dim currentConnection As SqlConnection = New SqlConnection(_connectionString)
Dim currentCommand As New SqlCommand

[code]....

View 1 Replies

Access Of Shared Member, Constant Member, Enum Memberor Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated?

Jun 23, 2009

i changed a class variable to shared so i can access it in all instances of the class, but it caused an error. what is causing this, and how can i fix it?

Private
Shared img As Bitmap
Me
.img = bgImage

View 2 Replies

Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

Jun 2, 2011

how do I overcome it? I have created a class and compiled into .dll This code

[Code]...

View 2 Replies

Warning 1: Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

May 31, 2010

In the following code i get a warning at line 59:Warning 1: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.and.. At line 78 I get this Warning:

Warning 2 Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

The program compiles and runs well, but i cant' undesrtand the reason for these warnings. Any Idea ?

1: Public Class Form1
2:
3: 'Form level members
4: Private objCustomers As New ArrayList

[code]....

View 5 Replies

Get "Object Reference Not Set To An Instance Of An Object" Error When Trying To Find An Instance In A String?

Jan 23, 2009

I am using the IndexOf function of the string class to find a specific instance of a string. And based on that I have a logic to do something. Below is the example of what I am doing. The code is in production and is working fine. But for some instance I am getting an "Object reference not set error". Yeah its intermittent.The requestXML is a string of xml data passed in as a paramter to a subroutine. I am fetching the xml string as a form post in a request object. The only thing I could think of getting this kind of error is when the requestXML string varia

requestXml = Request("requestXML")
SubmitRequest(requestXml)
Private
Sub SubmitRequest(ByVal requestXml

[code]....

View 5 Replies

Invoke An Instance Function Delegate On An Instance Of A Generic Type?

Aug 4, 2010

D is a dictionary whose entry values are of Type T..What I'm attempting to do is have a delegate like "Serializer" below that I can invoke on an instance of T, such as "Entry.Value" below.Please see the "return Entry..." line below for my wishful thinking.[code]

View 2 Replies

Use Shared Vs Instance References?

Mar 3, 2010

As I stated before in my Sorting questions.When is it advisable to use Shared Functions vs Instance Functions References.The problem I posed was that in a threaded application if I was sorting an array of 999999999 elements I typically want to call a shared function that handles this; however in .NET the way to sort is through a .Sort method which you pass an array to be sorted and a function handler; or Comparisson(t of).

My impression is that if in order to do a ClosestToN Sort I would have to calculate the value of N in the array first; then sort and then subtract the value of N from the sorted array.JohnH suggested passing the value of N as a Property in a Class that contained a reference to a sort Algorithm.The benchmark suggested in a 1 thread model it would work faster (which I knew that it would through math, but the accessors I was speculative on; I turned out to be wrong it worked fine either way).

My issue is in a Multi-Thread application creating instances for an accessor may cause memory to fill quickly if I am dealing with 1000's of threads.Is it better in this case to use a slower Shared function, then a faster Instance Function?

View 5 Replies

How Many Instance Will A Shared Variable Be Created

Apr 7, 2010

How many instances of a shared variable will be created in a class? just one? correct

[code]...

So, in other words, the DocumentDelivery class will only have one instance of RenderList, correct? can somebody confirm?

View 3 Replies

Is There Function Takes Name Of Instance And Return Instance

Feb 29, 2012

I was trying to fill 10 checkedlistboxes with items..So I made a sub with 2 arguments like this Private Sub fill_checkedlistboxes(ByVal items As String, ByVal checkedlistbox As CheckedListBox) End sub the first argument items is a long string whitch splits in the sub into many strings and added them all into the second arguments (thecheckedlistbox) I want to make for next statement to fill all the 10 checkedlistboxes in my form with an 10 long strings held in an array called strings, so i write something like this [code] What i have to write in the "?????" area to have the checkedlistbox that i want? the checkedlistboxes names are checkedlistbox 1, 2 , 3 ....10

View 12 Replies

Ajax - Passing Instance To Shared Method In .NET?

Nov 4, 2010

I have been thrown in at the deep end with an existing VB.NET project at work. I have never used VB.NET before so I am struggling a little. Does anyone know how to solve the following.I need to pass an instance to client side and then pass it to a shared method in order to access instance methods from when the shared method.The starting point is a fileupload control within the HTML of my Contacts.aspx file:

<asp:FileUpload ID="DocUpload1" runat="server" onchange="CallMe();" />

The onchange event calls a javascript method, see below, this uses AJAX PageMethods to called a Shared method in my code behind This is the script code which is in my Contact.aspx file

[Code]...

If anyone knows the solution please could they update the code as I probably won't be able to understand if you just give a description. I just hope I am along the right tracks.

View 1 Replies

VS 2010 : Exposing An Instance Property As Shared?

May 24, 2010

Suppose I have a class of objects called Porky with a property called IsHuge:

Public Class Porky
Public Property IsHuge As Boolean
End Class

Now I want to make a special kind of Porky -- let's call it UberPorky -- for which I want to change ALL instances to either IsHuge or not IsHuge. What I'd like to do is this:

Public Class UberPorky
Inherits Porky
Public Overrides Shared Property IsHuge As Boolean

[code]....

The trouble is, I can't do that. I'm not allowed to reference MyBase or Me in a Shared property.

View 17 Replies

.net - Prohibit An Instance From Calling Shared/Static Method?

Aug 27, 2010

Is it possible to prohibit an instance of a class from calling a shared/static method?

For example:

I want to allow this:

ClassName.MethodOne()

But I want to disallow this:

Dim A As New ClassName
A.MethodOne()

The reason this is desirable is that in this case it is semantically confusing if an instance can call the method.

View 2 Replies

Overload Shared Methods On Non-instance Types Using Extensions?

May 14, 2012

I want to extend the BitConverter class with an overload of ToString() that takes a parameter of type Char, representing a value delimiter.Why? By default, the ToString() call returns a string representation of a byte array, delimited by dash symbols. The signature does not allow you to specify a different delimiter, which I find very unfortunate.Now because this is not an instance type, or maybe because I'm overloading a shared method, I'm having a hard time finding the proper syntax to define my extension method.What am I doing wrong here, causing the overloads to not show up in IntelliSense:

Imports System.Runtime.CompilerServices
Module BitConverterExtensions
<Extension()>

[code].....

View 1 Replies

Purpose Of Using Shared Methods That Return An Instance Of A Class?

Oct 11, 2010

What is the purpose of using shared methods that return an instance of a class, as opposed to a constructor?

ie: in VB.net, the system.drawing.color class has shared method "FromArgb(int, int, int) as color". This is different from java's implementation which simply is a constructor that takes three ints. Why the decision to do one or the other?

View 1 Replies

Getting The Local Instance Of SQL Server Rather Than A Named Instance

Jul 29, 2010

A while ago, I wrote a web-based guestbook application that wrote it's own database.

My code was very amateurish, but, as it was my very first publication, I was very happy with it. Only about a month after I'd published it did I realize I'd made a huge mistake in the code.

I've only ever connected to a specific named instance of SQL Server, and it occurred to me that, if the SQL Server instance has a different name than the one I specified, it wouldn't work.

So, since my users will probably not know what the name of the instance of SQL Server that's running is, I thought adding a field where the user can specify it would help if they do, but what if they don't? My answer was to get the local instance, regardless of name.

I tried Data Source=.local;, Data Source=.; and other variants, but nothing worked.

View 2 Replies

Moving Large Instance Method To Shared And Creating Stub?

Jun 5, 2011

If I have a very large function/sub in a class that is an instance method (i.e., not Shared), do I gain or lose anything by moving that to a shared method and then declaring a small stub method for the instance use?

I.e., I go from this:
Public Sub MyBigMethod(ByVal Foobar As String)
If String.IsNullOrWhitespace(Foobar) Then
Throw New ArgumentNullException("Foobar")
End If
[Code] .....

My thinking is I save on memory size per each instance of the object. Because each instance only has to lug around the stub method which handles calling the shared version and passing an instance of itself to the shared method so that it can do whatever it needs to do. But I'll wager that I sacrifice a very teensy amount of speed because of the added function call overhead.

View 1 Replies

Very Simple Ssis Script Transformation Giving Object Reference Not Set To An Instance Of An Object

Mar 1, 2012

I have an ssis package that takes a flat file and dumps it to SQL. During that process, 150 columns need to have '-' and '.' removed from them. I have done this using a Script Transformation.

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Dim column As IDTSInputColumn90
Dim rowType As Type = Row.GetType()

[code]....

Edit I've discovered that this line is the problem

Dim strCol As String = columnValue.GetValue(Row, Nothing).ToString()

View 1 Replies

.net - Process.start System.nullreferenceexception: Object Reference Not Set To An Instance Of An Object

Oct 16, 2011

I am trying to start the process with the following parameters When I try to start it though I get an System.nullreferenceexception: Object reference not set to an instance of an object

Dim exepath As String = Application.StartupPath + "inffmpeg.exe"
Dim sr As StreamReader
Dim cmd As String = " -i """ + input + """ -ar 22050 -y """ + output + """"
Dim ffmpegOutput As String

[code]....

View 16 Replies

Asp.net - Checking For A Session Variable... Returns (Object Reference Not Set To An Instance Of An Object)

Jan 12, 2011

In the Session_Start of the Global.asax i have

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Session("login") = False

[code]....

Why i am getting error the error Object reference not set to an instance of an object. at line

If Current.Session("login") Is Nothing Then

while checking for the login state as follows?

If GetLogin = False Then
'Do something
End if

I mean i have already created the instance on the Session_Start... Haven't i?

View 1 Replies

Error System.NullReferenceException Occurred - Object Reference Not Set To An Instance Of An Object

Jan 12, 2010

i am using VB.net 2003 and i am trying to get the number of rows of a dataset from form1 into form2 in order to use it for something else and i am getting the error"System.NullReferenceException occured...Additional information: object reference not set to an instance of an object"...my code is like this:in form1:Public x as integer= me.dataset.table.rows.count here it gives me the error

in form2:
dim frm as new form1
msgbox(frm.x)

View 1 Replies

Error: System.NullReference Exception: Object Reference Not Set To An Instance Of An Object

Jan 5, 2010

I am getting this error when I try to print my report. Here is my print code.

Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim Print_Dialog As New PrintDialog

[code].....

Here is my error: System.NullReference Exception: Object reference not set to an instance of an object.

View 1 Replies

Format Date In Data Grid View Object Not Set To An Instance Of An Object?

Jan 29, 2012

I'm trying to set the format of a column in a datagridview.When I put the format statement in the on load event for the form, it has no effect. When I put it in the cellformatting event I get the "Object reference not set to an instance of an object" error. I checked the column name. What I am doing wrong?

This is the code:Private Sub MeetingTblDataGridView_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles MeetingTblDataGridView.CellFormatting
Me.MeetingTblDataGridView.Columns("Starttime").DefaultCellStyle.Format = "HH:mm:ss"
End Sub What I'm trying to do is get rid of the date part of a Date/Time field (stored in an Access database) in a datagridview column.

dp.SyntaxHighlighter.ClipboardSwf = '/dp.SyntaxHighlighter/Scripts/clipboard.swf'
dp.SyntaxHighlighter.HighlightAll('09dde30f062e451a854266e66205b1cf')

View 10 Replies

Line Of Code Is Generating This Error - Object Reference Not Set To An Instance Of An Object?

Aug 14, 2010

with datagridview1

while looping through all the cells

i am trying to allot a cell value to another cell value basing on some conditions
& finally delete one column.my code is as fallows

Dim i, x As Integer
i = 0
x = Me.DataGridView1.Rows.Count[code]....

error i am getting is : Object reference not set to an instance of an object.it is extremely surprising for me the same code has worked nice for me but why & how the same line of code is generating this error.

View 10 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved