Erro ao fazer INSERT into DB (ASP.NET VB)

Boa noite, eu estou a construir um website em VB.net e ainda sou novo nesta linguagem, ontem procurava na internet por um código vb para gravar dados na BD usando uma página ASP.net com um WebForm e vim parar aqui ao fórum numa dica do "alfinete" se não estou em erro.
Contudo eu alterei o código para as minhas especificações e deveria estar a funcionar mas ao invés está a gerar um erro, o meu código é este:
Código:
[SIZE=2][COLOR=#0000ff]Partial[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2][COLOR=#000000] _Default[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] System.Web.UI.Page
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sda [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlDataAdapter
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ligacao2, strsql [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ds [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Data.DataSet
[/SIZE][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btn_registar_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Web.UI.ImageClickEventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btn_registar.Click
 
 
[/SIZE][SIZE=2][COLOR=#008000]'**************************************************************************************
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'CONSULTA À BD PELO REGISTO ENVIADO
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'**************************************************************************************
[/COLOR][/SIZE][SIZE=2]ligacao2 = [/SIZE][SIZE=2][COLOR=#a31515]"RSLConnectionString1"
 
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'faz a respectiva seleccção a base de dados para detectar o 
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'utilizador que foi digitado na caixa de texto
[/COLOR][/SIZE][SIZE=2]strsql = [/SIZE][SIZE=2][COLOR=#a31515]" SELECT [email] FROM [newsletter] WHERE [email] ='"[/COLOR][/SIZE][SIZE=2] & [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].email.Text & [/SIZE][SIZE=2][COLOR=#a31515]"'"
 
[/COLOR][/SIZE][SIZE=2]sda = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlDataAdapter(strsql, ligacao2)
ds = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.DataSet()
sda.Fill(ds)
sda.Dispose()
[/SIZE][SIZE=2][COLOR=#008000]'**************************************************************************************
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' SCRIPT DE LIGAÇÃO E GRAVAÇÃO NA BD DOS DADOS DA NEWSLETTER
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'**************************************************************************************
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ligacao, insere_sql, num
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] table [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Data.DataTable
[/SIZE][SIZE=2][COLOR=#008000]' Dim cont As Integer
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' faz a ligação a base de dados
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'**************************************************************************************
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' verifica se o que foi digitado na caixa de texto é igual a string de pesquiza
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' strsql feita a cima para detectar se o utilizador ja existe ou não na bd
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' caso exista faz o seu registo
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' caso contrario diz que ja existe 
 
[/COLOR][/SIZE][SIZE=2]table = ds.Tables.Item(0)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cont [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = table.Rows.Count
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] cont = 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
 
[/COLOR][/SIZE][SIZE=2]ligacao = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlConnection([/SIZE][SIZE=2][COLOR=#a31515]"RSLConnectionString1"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#008000]' abre a ligação
[/COLOR][/SIZE][SIZE=2]ligacao.open()
 
[/SIZE][SIZE=2][COLOR=#008000]' faz o sql para inserir cada string inserida no campo respectivo
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' da bd
[/COLOR][/SIZE][SIZE=2]insere_sql = [/SIZE][SIZE=2][COLOR=#a31515]"Insert into newsletter ("[/COLOR][/SIZE][SIZE=2] & _
[/SIZE][SIZE=2][COLOR=#a31515]" nome, email, telefone )"[/COLOR][/SIZE][SIZE=2] & _
[/SIZE][SIZE=2][COLOR=#a31515]" values (@nome, @email, @telefone)"
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' comando para executar a ligação
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] comando [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlCommand = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlCommand(insere_sql, ligacao)
[/SIZE][SIZE=2][COLOR=#008000]' cria as variaveis tipo sql parameter associadas aos respectivos tipos
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] nome [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlParameter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlParameter([/SIZE][SIZE=2][COLOR=#a31515]"@nome"[/COLOR][/SIZE][SIZE=2], System.Data.SqlDbType.NVarChar)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] email [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlParameter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlParameter([/SIZE][SIZE=2][COLOR=#a31515]"@email"[/COLOR][/SIZE][SIZE=2], System.Data.SqlDbType.NVarChar)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] telefone [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlParameter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Data.SqlClient.SqlParameter([/SIZE][SIZE=2][COLOR=#a31515]"@telefone"[/COLOR][/SIZE][SIZE=2], System.Data.SqlDbType.NVarChar)
[/SIZE][SIZE=2][COLOR=#008000]'atribui o valor inserido no formulario de cada caixa de texto 
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' a variavel criada a cima
[/COLOR][/SIZE][SIZE=2]nome.Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].nome.Text
email.Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].email.Text
telefone.Value = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].telefone.Text
[/SIZE][SIZE=2][COLOR=#008000]' adiciona o valor guardado nessa variavel no respectivo campo da bd
[/COLOR][/SIZE][SIZE=2]comando.Parameters.Add(nome)
comando.Parameters.Add(email)
comando.Parameters.Add(telefone)
num = comando.ExecuteNonQuery
[/SIZE][SIZE=2][COLOR=#008000]' se existir ligação guarda os dados , caso contrario da mesnagem de erro
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] num = 1 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].erro.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].erro.Text = [/SIZE][SIZE=2][COLOR=#a31515]"O Utilizador "[/COLOR][/SIZE][SIZE=2] & [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].nome.Text & [/SIZE][SIZE=2][COLOR=#a31515]" foi Registado com sucesso"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].nome.Text = [/SIZE][SIZE=2][COLOR=#a31515]""
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].email.Text = [/SIZE][SIZE=2][COLOR=#a31515]""
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].telefone.Text = [/SIZE][SIZE=2][COLOR=#a31515]""
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].erro.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].erro.Text = [/SIZE][SIZE=2][COLOR=#a31515]" Erro na interligação de dados"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]ligacao.close()
 
 
[/SIZE][SIZE=2][COLOR=#0000ff]Else
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].erro.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].erro.Text = [/SIZE][SIZE=2][COLOR=#a31515]" Esse email já existe na nossa base de dados "
 
 
 
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
End[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Class
[/COLOR][/SIZE]
Este é o fichiero newsletter.aspx.vb, no ficheiro newsletter.aspx tenho então o WebForm que enviará os dados para serem processados, mas estou a receber este erro:

O formato da cadeia de inicialização não está em conformidade com a especificação no início do índice 0.

[FONT=Arial, Helvetica, Geneva, SunSans-Regular, sans-serif]Descrição: Excepção não processada ao executar o pedido Web actual. Consulte o rastreio da pilha para obter mais informações sobre o erro e o respectivo ponto de origem no código.

Detalhes da excepção: System.ArgumentException: O formato da cadeia de inicialização não está em conformidade com a especificação no início do índice 0.[/FONT]

No rastreio da pilha tenho estes dados:

Código:
[ArgumentException: O formato da cadeia de inicialização não está em conformidade com a especificação no início do índice 0.]
   System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +1242
   System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +128
   System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +102
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +52
   System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +24
   System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +125
   System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) +56
   System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +4
   System.Data.SqlClient.SqlConnection..ctor(String connectionString) +21
   System.Data.SqlClient.SqlDataAdapter..ctor(String selectCommandText, String selectConnectionString) +51
   _Default.btn_registar_Click(Object sender, ImageClickEventArgs e) +85
   System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +105
   System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +115
   System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

A estrutura da tabela "newsletter" que está referida acima é a seguinte:
ID > int (autoincrement) | nome > nvarchar(MAX) | email > nvarchar(MAX) | telefone > nvarchar(MAX)

Alguém me pode ajudar é que eu não estou a ver qual é o erro aqui??? Agradeço desde já.

Um abraço,

Eduardo Ribeiro
 
Erro corrigido

Aqui fica a resposta para que em situações futuras não volte a acontecer:

O meu problema estava na definição de ligação à base de dados, eu estava a utilizar o nome definido para a minha Connection String e o motor do ASP.NET não estava a reconhecê-la, bastou para isso inserir a Connection String na integra:

Código:
[SIZE=2][COLOR=#a31515]Data Source=SQLSERVERNAME\SQLEXPRESS;Initial Catalog=NOMEdaBD;Persist Security Info=True;User ID=SA;Password=********
[/COLOR][/SIZE]

De qualquer forma obrigado pela atenção dispensada.

Abraço,
Eduardo Ribeiro
 
Back
Topo