22 messaggi dal 11 settembre 2011
Salve a tutti.
Ho creato una pagina che deve fare il login a un'area riservata del sito.

Inserendo i dati username e password, viene fatto il controllo su una tabella del db.
Se i dati sono presenti allora entro nell'area riservata.
Nella pagina di login ho dichiarato la stringa di connessione da utilizzare che è memorizzata nel web.config.
Utilizzo un database MYSQL.



Ho questo problema, quando faccio click sul bottone di accesso:

-----------------------------------------------------------------

Server Error in '/' Application.

Format of the initialization string does not conform to specification starting at index 0.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error:


Line 14: Dim query As String = "<%$ConnectionString:gdlgestionaledb%>"
Line 15:
Line 16: conn = New OdbcConnection(query)
Line 17: conn.Open()
Line 18:

Source File: C:\Inetpub\vhosts\gdl-connect.eu\httpdocs\Login.aspx Line: 16
-------------------------------------------------------------------

Grazie dell'aiuto.

Il codice della pagina che va in errore è il seguente:


<%@ Page Language="VB" Debug="true"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim conn As OdbcConnection
Dim cmd As OdbcCommand
Dim dr As OdbcDataReader
Dim query As String = "<%$ConnectionString:gdlgestionaledb%>"

conn = New OdbcConnection(query)
conn.Open()

cmd = New OdbcCommand("SELECT id FROM connect_clienti", conn)
dr = cmd.ExecuteReader
dr.Close()
conn.Close()
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 55%;
}
.style2
{
width: 43%;
}
.style3
{
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>

<table align="center" class="style1">
<tr>
<td align="center">
<img alt="" src="immagini/GdlConnect.jpg" /></td>
</tr>
<tr>
<td align="center">

<table class="style2">
<tr>
<td align="right" class="style3">
Codice utente</td>
<td>
<asp:TextBox ID="Username" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Codice utente non inserito" Text="*" ControlToValidate="UserName" ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style3">
Password:</td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Password non inserita" Text="*" ControlToValidate="Password"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style3">
&nbsp;</td>
<td align="left">
<asp:Button ID="Button1" runat="server" Text="Accedi" BackColor="#663333"
BorderColor="#663333" ForeColor="White" onclick="Button1_Click" />
</td>
</tr>
<tr>
<td align="left" colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Elenco errori:" ForeColor="Red" >
</asp:ValidationSummary>
</td>
</tr>
</table>

</td>
</tr>
<tr>
<td align="center">
<img alt="" src="immagini/GdlStudio.jpg" /></td>
</tr>
</table></div>
</form>
</body>
</html>
Dim query As String = "<%$ConnectionString:gdlgestionaledb%>"
Questo mi sembra strana: "<%$ConnectionString:gdlgestionaledb%>"

per accedere alla connectionstring nel web config:

System.Configuration.ConfigurationManager.ConnectionStrings("gdlgestionaledb").ConnectionString
prova cosi...
22 messaggi dal 11 settembre 2011
Ho provato come dici tu:

Dim conn As OdbcConnection
Dim cmd As OdbcCommand
Dim dr As OdbcDataReader
Dim query As String = System.Configuration.ConfigurationManager.ConnectionStrings("gdlgestionaledb").ConnectionString

conn = New OdbcConnection("query")
conn.Open()



Mi dà sempre questo errore:

Format of the initialization string does not conform to specification starting at index 0.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error:

(MI SEGNA ERRORE ALLA RIGA 17)

Line 15: Dim query As String = System.Configuration.ConfigurationManager.ConnectionStrings("gdlgestionaledb").ConnectionString
Line 16:
Line 17: conn = New OdbcConnection("query")
Line 18: conn.Open()
Line 19:

Source File: C:\Inetpub\vhosts\gdl-connect.eu\httpdocs\Login.aspx Line: 17

Stack Trace:


[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +4872602
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +129
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +98
System.Data.Odbc.OdbcConnectionString..ctor(String connectionString, Boolean validate) +36
System.Data.Odbc.OdbcConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +36
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +200
System.Data.Odbc.OdbcConnection.ConnectionString_Set(String value) +62
System.Data.Odbc.OdbcConnection.set_ConnectionString(String value) +4
System.Data.Odbc.OdbcConnection..ctor(String connectionString) +24
ASP.login_aspx.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\vhosts\gdl-connect.eu\httpdocs\Login.aspx:17
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Modificato da nanu1973 il 23 marzo 2012 11.36 -
Private Sub InsertRow(ByVal connectionString As String)

    Dim queryString As String = _
        "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')"
    Dim command As New OdbcCommand(queryString)

    Using connection As New OdbcConnection(connectionString)
        command.Connection = connection
        connection.Open()
        command.ExecuteNonQuery()

        ' The connection is automatically closed at 
        ' the end of the Using block.
    End Using
End Sub


questo è un esempio....
Comunque sembrerebbe un errore di accesso al database..
22 messaggi dal 11 settembre 2011
Ho verificato la connessione. Ora funziona, mettendo il tuo suggerimento.
Grazie
nanu1973 ha scritto:
Ho verificato la connessione. Ora funziona, mettendo il tuo suggerimento.
Grazie

Perfetto.

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.