Fórmulas e Cenas

Object Reference Not Set to an Instance of an Object

  Home  |   Contact  |   Syndication    |   Login
  45 Posts | 0 Stories | 15 Comments | 0 Trackbacks

News

Archives

Post Categories

Links

Monday, May 19, 2014 #

If you are unable to access all jnlp files on your site, chances are that the myme type for jnlp files is not defined in IIS.

On your site you need to add a new Mime Type using:
  • Extension: .jnlp
  • Mime Type: application/x-java-jnlp-file

Hope this helps


Monday, October 14, 2013 #

select
	*
FROM
	information_schema.tables
where
	table_schema='YourSchema'

Tuesday, January 22, 2013 #

When you are inserting into a table using entity framework, on rare occasions you might get the following error:

 {System.Data.OptimisticConcurrencyException: Store update, insert, or delete statement affected an unexpected number of rows (0)

 

This happened to me because of an "instead of  INSERT" trigger that was active on the page. It turns out that EF does not go well with triggers, because it fails to get the inserted ID.

For me, the solution was to change the trigger so that the last executed code was a select, something like this:

select top 1 id from MyTable order by id desc

 

Hope this helps you :)

 


Monday, October 22, 2012 #

Restoring a database can be a pain in the ass, specially when you need to find some point in time where the data went wrong.

This is the best way i know how:

RESTORE DATABASE MY_TARGET_DATABASE FROM DISK = 'path_to_backup.bak' 
WITH NORECOVERY, replace
GO
RESTORE LOG MY_TARGET_DATABASE FROM DISK = 'mytransaction_log1.trn' WITH NORECOVERY
GO
RESTORE LOG MY_TARGET_DATABASE FROM DISK = 'mytransaction_log2.trn' WITH NORECOVERY
go
RESTORE LOG MY_TARGET_DATABASE FROM DISK = 'mytransaction_log3.trn' WITH NORECOVERY
go
RESTORE LOG MY_TARGET_DATABASE FROM DISK = 'mytransaction_log4.trn' WITH RECOVERY,
STOPAT = '2012-08-31 14:10:00' 
go


Tuesday, October 2, 2012 #

DataView view = new DataView(table);
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...);

 

Source: http://stackoverflow.com/questions/1199176/how-to-select-distinct-values-from-datatable


Wednesday, April 18, 2012 #

Simple and direct:

myContainer.myEntity.Where("it.myField LIKE '%' + @searchTerm + '%'", new ObjectParameter("searchTerm", myQueryText));


Monday, December 19, 2011 #

If you have a "{" or "}" inside a string when using string.format you will get the error mentioned in the title.

To fix this you must double the charater.

Error Example: 
string teste = string.Format(" This is a {teste} {0} ", mystring);

Correct Example:
string teste = string.Format(" This is a {{teste}} {0} ", mystring);v

Tuesday, September 20, 2011 #

In global.asax:

 

protected void Application_BeginRequest(Object sender, EventArgs e)
{
	HttpRuntimeSection runTime = (HttpRuntimeSection)WebConfigurationManager.GetSection("system.web/httpRuntime");
	//Approx 100 Kb(for page content) size has been deducted because the maxRequestLength proprty is the page size, not only the file upload size
	int maxRequestLength = (runTime.MaxRequestLength - 100* 1024;
 
	//This code is used to check the request length of the page and if the request length is greater than 
	//MaxRequestLength then retrun to the same page with extra query string value action=exception

	HttpContext context = ((HttpApplication)sender).Context;
	if(context.Request.ContentLength > maxRequestLength)
	{
		IServiceProvider provider = (IServiceProvider)context;
		HttpWorkerRequest workerRequest = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
		// Check if body contains data
		if(workerRequest.HasEntityBody())
		{
			// get the total body length
			int requestLength = workerRequest.GetTotalEntityBodyLength();
			// Get the initial bytes loaded
			int initialBytes = 0;
			if(workerRequest.GetPreloadedEntityBody() != null)
				initialBytes = workerRequest.GetPreloadedEntityBody().Length;
			if(!workerRequest.IsEntireEntityBodyIsPreloaded())
			{
				byte[] buffer = new byte[512000];
				// Set the received bytes to initial bytes before start reading
				int receivedBytes = initialBytes;
				while(requestLength - receivedBytes >= initialBytes)
				{
					// Read another set of bytes
					initialBytes = workerRequest.ReadEntityBody(buffer, buffer.Length);
					// Update the received bytes
					receivedBytes += initialBytes;
				}
				initialBytes = workerRequest.ReadEntityBody(buffer, requestLength - receivedBytes);
			}
		}
		// Redirect the user to the same page with querystring action=exception. 
		context.Response.Redirect("~/Erros/FicheiroGrande.aspx");
	}
}

 

Source

<script type="text/javascript" language="javascript">

        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(refresh);

        function refresh() { //Your code here; }

</script>

 

Source


Thursday, June 16, 2011 #

/* Processes that are blocking others */
select * from 
sysprocesses
where spid in
(
select 
	blocked
from 
	syslocks l
	inner join sysprocesses p on p.spid=l.spid
where 
	p.dbid=5 -- Database ID
	and p.blocked<>0
)

/* Processes being blocked*/
select 
	p.*
from 
	syslocks l
	inner join sysprocesses p on p.spid=l.spid
where 
	p.dbid=5
	and p.blocked<>0