Pesquisa

sábado, 14 de dezembro de 2013

CREATE DATABASE permission denied in database 'master'

1.  shut down SQL Server from services

2.  open cmd window (as admin) and run single-user mode as local admin with this command:
"c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -m -s SQLEXPRESS

3.  open another cmd window (as admin)

4.  open sqlcmd:
sqlcmd -S .\SQLEXPRESS
Now add the sysadmin user:
a.  sp_addsrvrolemember 'domain\user', 'sysadmin'
b.  GO

5.  now Ctrl+C the single-user mode from the first cmd window to kill SQL Server.  Now restart it from services the normal way.  Log into Management Studio and the user you created should be listed under logins with the credential of "sysadmin."

Fonte: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/76fc84f9-437c-4e71-ba3d-3c9ae794a7c4/sql-express-2008-r2-create-database-permission-denied-in-database-master?forum=sqlexpress

sábado, 7 de setembro de 2013

Gerando números aleatórios

Ao criar dois objetos Randon, no mesmo milisegundo, ocorrerá um problema. Todos os números gerados por ambos os objetos serão iguais.
A solução para isso é utilizar o método Sleep para dar um tempo de 3 milisegundos entre a criação de cada uma das instâncias dos objetos Randon, ou utilizar o mesmo objeto para gerar o outro número.

Random r1 = new Random();
Random r2 = new Random();
int a1 = r1.Next();
int a2 = r2.Next();

As variáveis a1 e a2 terão o mesmo valor.

Random r1 = new Random();
System.Threading.Thread.Sleep(3);
Random r2 = new Random();
int a1 = r1.Next();
int a2 = r2.Next();

As variáveis a1 e a2 terão valores diferentes.

Random r1 = new Random();
int a1 = r1.Next();
int a2 = r1.Next();

As variáveis a1 e a2 terão valores diferentes.

terça-feira, 20 de agosto de 2013

Fazendo uma requisição web

Através da classe HttpWebRequest é possível fazer uma requisição à qualquer página da web, podendo pegar todo o seu conteúdo HTML.

domingo, 26 de agosto de 2012

Foco após requisição Ajax

Para não perder o foco após uma requisição ajax do updatepanel é possível utilizar a função EndRequest.

var ID;

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

$("input.campo-texto1").live("focus", function () {
ID = $(this).attr('id');
});

function EndRequestHandler(sender, args) {
$('#' + ID).focus();
}



domingo, 8 de abril de 2012

ASP.NET AJAX v1.0 Sys is undefined error

“I have seen many blog entries and forum threads on this error however I was curious if anyone has any insight as to why this error seems to occur on Windows 2003 Server SP1 and not XP Pro SP2. I have not tested on Windows 2000 or 2003 without SP1.

When I deployed my application to the production server which is Windows Server 2003 SP1, I received this error after the ASP.NET AJAX 1.0 installation. Now I have never used a beta or RC release so this is the first time using ASP.NET AJAX in my application.

I turned to Google and I found the following:

if you are using Windows 2003 as web server then you'll face this "sys is undefined" error .to get rid of this weird problem follow the following steps:

  1. Open IIS and right click on your web site virtual directory and then click properties
  2. Then on virtual directory tab click on configuration button
  3. In mappings tab set the configuration like this.
    Executable: "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" - locate this dll file
    Extension: .axd
    Verbs: All Verbs
    Script Engine: checked
    Check that file exists: do not check this.
  4. Finally click OK.

The axd extension was in fact registered on the server but the Verbs was not set to allow all.”

Fonte: http://aspadvice.com/blogs/sswafford/archive/2007/01/25/ASP.NET-AJAX-v1.0-Sys-is-undefined-error.aspx

Navegar em todas as tabelas

SP que executa comandos SQL para cada uma das tabelas do banco de dados.
 
Acredite, pode ser útil.
 
http://weblogs.asp.net/nunogomes/archive/2008/08/19/sql-server-undocumented-stored-procedure-sp-msforeachtable.aspx

Exemplo:

exec sp_MSforeachtable @command1 = "select * from ?"

Multiupload de arquivo sem flash

Funciona no IE7 e 8 inclusive e vem com tutoriais para várias linguagens/frameworks.

http://blueimp.github.com/jQuery-File-Upload/

domingo, 1 de maio de 2011

Personalizando o HTML do UpdatePanel

Segue abaixo uma classe que tem como objetivo personalizar o HTML gerado a partir de um UpdatePanel.

namespace LeftSlipper {
using System;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.Web.UI;

public class CustomUpdatePanel : UpdatePanel {
private string _cssClass;
private HtmlTextWriterTag _tag = HtmlTextWriterTag.Div;

[DefaultValue("")]
[Description("Applies a CSS style to the panel.")]
public string CssClass {
get {
return _cssClass ?? String.Empty;
}
set {
_cssClass = value;
}
}

// Hide the base class's RenderMode property since we don't use it
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new UpdatePanelRenderMode RenderMode {
get {
return base.RenderMode;
}
set {
base.RenderMode = value;
}
}

[DefaultValue(HtmlTextWriterTag.Div)]
[Description("The tag to render for the panel.")]
public HtmlTextWriterTag Tag {
get {
return _tag;
}
set {
_tag = value;
}
}

protected override void RenderChildren(HtmlTextWriter writer) {
if (IsInPartialRendering) {
// If the UpdatePanel is rendering in "partial" mode that means
// it's the top-level UpdatePanel in this part of the page, so
// it doesn't render its outer tag. We just delegate to the base
// class to do all the work.
base.RenderChildren(writer);
}
else {
// If we're rendering in normal HTML mode we do all the new custom
// rendering. We then go render our children, which is what the
// normal control's behavior is.
writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
if (CssClass.Length > 0) {
writer.AddAttribute(HtmlTextWriterAttribute.Class, CssClass);
}
writer.RenderBeginTag(Tag);
foreach (Control child in Controls) {
child.RenderControl(writer);
}
writer.RenderEndTag();
}
}
}
}



Abaixo, a sua aplicação.



<%@ Register Namespace="LeftSlipper" TagPrefix="ls" %>
...
<ls:CustomUpdatePanel runat="server" ID="CustomUpdatePanel1"
CssClass="greenPanel" Tag="B">
<ContentTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
</ls:CustomUpdatePanel>

ls:CustomUpdatePanel runat="server" ID="CustomUpdatePanel1"
CssClass="greenPanel" Tag="B">
<ContentTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
</ls:CustomUpdatePanel>
And here's what got rendered with these settings (actual times may vary!):

<b id="CustomUpdatePanel1" class="greenPanel">
<span id="Label1">12/6/2006 9:18:07 PM</span>
<input type="submit" name="Button1" value="Button" id="Button1" />
</b>



Este mesmo princípio pode ser utilizado para modificar qualquer controle.


Javascript - Validação Client-Side

Artigo muito interessante sobre validações.

ASP.NET Validation in Depth

Segue abaixo um dos trechos do artigo, que fala sobre as funções javascript que existem para manipular os controles de validação.

ValidatorValidate(val)
Tem como parâmetro client-validator. Esta função faz com que o seja feito a verificação e que atualize de sua exibição.

ValidatorEnable(val, enable)
Tem como parâmetro um client-validator e um valor booleano. Esta função ativa ou desativa um client-validator.

ValidatorHookupControl(control, val)
Tem como parâmetro um elemento HTML e um client-validator. Esta função modifica ou cria o vínculo entre um controle e client-validator. Logo, é possível modificar os “apontamentos” entre controle e client-validator.

Além destre trecho, existem vários outros pontos abordados sobre validações.

Fonte: MSDN