Hi, Have you ever encountered this problem before? How to capture the reason of this error got when running the project?
Server Error in '/App2' 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:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034
I did follow this link
http://www.codeproject.com/Tips/424661/Access-Controls-from-ASP-NET-GridView-EmptyDataTem
to create these events/methods
protected void gv2_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("emptyInsert"))
{
tab2 ent = new tab2();
Boolean ret2;
GridViewRow emptyRow = gv2.Controls[0].Controls[0] as GridViewRow;
ent.rec_id = Convert.ToInt64(((TextBox)emptyRow.FindControl("gv_rec_id")).Text);
ent.user_id = Convert.ToInt64(((TextBox)emptyRow.FindControl("gv_user_id")).Text);
ent.int_desc = Convert.ToString(((DropDownList)emptyRow.FindControl("gv_int_desc")).Text);
ent.change_date = Convert.ToString(((DropDownList)emptyRow.FindControl("gv_change_date")).Text);
ret2= inserttab2(ent);
Filltab2Grid();
}
}
public List<tab2> gettab2List()
{
List<tab2> eList = new List<tab2>();
tab2 objInt = null;
string queryString = "SELECT [rec_id],[user_id],[int_desc],[change_date] FROM [dbo].[tab2]";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Mssqlconn2"].ConnectionString))
{
using (SqlCommand command = new SqlCommand(queryString, connection))
{
command.Connection.Open();
using (SqlDataReader dataReader = command.ExecuteReader())
{
while (dataReader.Read())
{
objInt = new tab2();
objInt.rec_id = Convert.ToInt64(dataReader["rec_id"]);
objInt.user_id = Convert.ToInt64(dataReader["user_id"]);
objInt.int_desc = Convert.ToString(dataReader["int_desc"]);
objInt.change_date = Convert.ToString(dataReader["change_date"]);
eList.Add(objInt);
}
}
}
}
return eList;
}
if (cmd.ExecuteNonQuery() >= 1) // if it returned 1 it means one (or more) row has been updated, otherwise no change made in DB
ret=true;
else
ret=false;
}
catch (Exception ex)
{
//lb_msg.Text = ex.Message;
ret = false;
//return;
}
finally
{
//lb_msg.Text = "";
conn.Close();
}
return ret;
}
...
Thanks a lot. Here is the connection.
<connectionStrings>
<add name="Conn2" connectionString="Data Source=192.168.168.1\ss2012;Initial Catalog=my_schema;Integrated Security=False;User ID=login2;Password=????? providerName="System.Data.SqlClient"/>
</connectionStrings>
I also have the same connection in other projects and don't have any problem to run it at all!
One thing strange is, when I directly debug the project in the client machine, I see no problem. Why do I get the error, when running the deployed project in the server?
The Connection String seems alright. The only thing that I could think that the deployed location isn't able to access the server hosting the database (your 192.168.168.1 address) or possibly some kind of permissions issue.
wmec
Contributor
6195 Points
3214 Posts
Format of the initialization string does not conform to specification starting at index 0
Feb 16, 2013 02:43 AM|LINK
Hi,
Have you ever encountered this problem before? How to capture the reason of this error got when running the project?
Server Error in '/App2' 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:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
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) +6713793
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +253
System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +134
System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +103
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) +35
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +294
System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) +60
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) +89
System.Web.UI.WebControls.SqlDataSource.CreateConnection(String connectionString) +49
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +209
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +28
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +313
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +146
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +192
System.Web.UI.Control.EnsureChildControls() +189
System.Web.UI.Control.PreRenderRecursiveInternal() +60
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Control.PreRenderRecursiveInternal() +222
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4297
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18034
I did follow this link
http://www.codeproject.com/Tips/424661/Access-Controls-from-ASP-NET-GridView-EmptyDataTem
to create these events/methods
protected void gv2_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("emptyInsert"))
{
tab2 ent = new tab2();
Boolean ret2;
GridViewRow emptyRow = gv2.Controls[0].Controls[0] as GridViewRow;
ent.rec_id = Convert.ToInt64(((TextBox)emptyRow.FindControl("gv_rec_id")).Text);
ent.user_id = Convert.ToInt64(((TextBox)emptyRow.FindControl("gv_user_id")).Text);
ent.int_desc = Convert.ToString(((DropDownList)emptyRow.FindControl("gv_int_desc")).Text);
ent.change_date = Convert.ToString(((DropDownList)emptyRow.FindControl("gv_change_date")).Text);
ret2= inserttab2(ent);
Filltab2Grid();
}
}
public List<tab2> gettab2List()
{
List<tab2> eList = new List<tab2>();
tab2 objInt = null;
string queryString = "SELECT [rec_id],[user_id],[int_desc],[change_date] FROM [dbo].[tab2]";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Mssqlconn2"].ConnectionString))
{
using (SqlCommand command = new SqlCommand(queryString, connection))
{
command.Connection.Open();
using (SqlDataReader dataReader = command.ExecuteReader())
{
while (dataReader.Read())
{
objInt = new tab2();
objInt.rec_id = Convert.ToInt64(dataReader["rec_id"]);
objInt.user_id = Convert.ToInt64(dataReader["user_id"]);
objInt.int_desc = Convert.ToString(dataReader["int_desc"]);
objInt.change_date = Convert.ToString(dataReader["change_date"]);
eList.Add(objInt);
}
}
}
}
return eList;
}
private void Filltab2Grid()
{
List<tab2> objIntList = new List<tab2>();
objIntList = gettab2List();
gv2.DataSource = objIntList;
gv2.DataBind();
}
public Boolean inserttab2(tab2 ent)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Mssqlconn2"].ConnectionString);
conn.Open();
SqlCommand cmd;
Boolean ret;
try
{
cmd = new SqlCommand("INSERT INTO [tab2] ([rec_id], [user_id], [int_desc],[change_date]) " +
"VALUES (" + ent.rec_id + ", " + ent.user_id + ", '" + ent.int_desc + "',cast('" + ent.change_date + "' as datetime))", conn);
if (cmd.ExecuteNonQuery() >= 1) // if it returned 1 it means one (or more) row has been updated, otherwise no change made in DB
ret=true;
else
ret=false;
}
catch (Exception ex)
{
//lb_msg.Text = ex.Message;
ret = false;
//return;
}
finally
{
//lb_msg.Text = "";
conn.Close();
}
return ret;
}
...
for this GV.
<asp:GridView ID="gv2" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="rec_id"
DataSourceID="SqlDataSource2" Width="232px" BorderStyle="Inset"
onrowcommand="gv2_RowCommand">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True"
ShowSelectButton="True" />
<asp:BoundField DataField="rec_id" HeaderText="rec_id" InsertVisible="False"
ReadOnly="True" SortExpression="rec_id" />
<asp:BoundField DataField="user_id" HeaderText="user_id"
SortExpression="user_id" />
<asp:BoundField DataField="int_desc" HeaderText="Description"
SortExpression="int_desc" />
<asp:BoundField DataField="change_date" HeaderText="Edit On"
SortExpression="change_date" />
</Columns>
<EmptyDataTemplate>
<table class="grid" cellspacing="0" rules="all" border="1" id="gvEG" style="border-collapse: collapse;">
<tr>
<th align="left" scope="col">
Record
</th>
<th align="left" scope="col">
User
</th>
<th align="left" scope="col">
Desc
</th>
<th align="left" scope="col">
Date
</th>
</tr>
<tr class="gridRow">
<td colspan="4">
No Records found...
</td>
</tr>
<tr class="gridFooterRow">
<td>
<asp:TextBox ID="gv_rec_id" runat="server" MaxLength="6" Width="50px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="gv_user_id" runat="server" Width="90px"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="gv_int_desc" runat="server" Width="100px" />
</td>
<td>
<asp:TextBox ID="gv_change_date" runat="server" Width="100px" />
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:Mssqlconn2 %>"
DeleteCommand="DELETE FROM [tab2] WHERE [rec_id] = @rec_id"
InsertCommand="INSERT INTO [tab2] ([user_id], [int_desc], [change_date]) VALUES (@user_id, @int_desc, @change_date)"
SelectCommand="SELECT * FROM [tab2]"
UpdateCommand="UPDATE [tab2] SET [user_id] = @user_id, [int_desc] = @int_desc, [change_date] = @change_date WHERE [rec_id] = @rec_id">
<DeleteParameters>
<asp:Parameter Name="rec_id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="user_id" Type="Int32" />
<asp:Parameter Name="int_desc" Type="String" />
<asp:Parameter Name="change_date" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="user_id" Type="Int32" />
<asp:Parameter Name="int_desc" Type="String" />
<asp:Parameter Name="change_date" Type="DateTime" />
<asp:Parameter Name="rec_id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
HuaMin Chen
wmec
Contributor
6195 Points
3214 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 17, 2013 08:16 AM|LINK
Dear all,
Any help to this?
HuaMin Chen
wmec
Contributor
6195 Points
3214 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 18, 2013 12:26 AM|LINK
Dear all,
Any help to this?
HuaMin Chen
Rion William...
All-Star
26445 Points
4389 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 18, 2013 01:27 AM|LINK
What does your Connection String (Mssqlconn2) look like? Because this error is likely stemming from an error within it.
Visit ConnectionStrings.com to double-check that it is all correct and in the proper format.
wmec
Contributor
6195 Points
3214 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 18, 2013 01:58 AM|LINK
Thanks a lot. Here is the connection.
<connectionStrings>
<add name="Conn2" connectionString="Data Source=192.168.168.1\ss2012;Initial Catalog=my_schema;Integrated Security=False;User ID=login2;Password=????? providerName="System.Data.SqlClient"/>
</connectionStrings>
I also have the same connection in other projects and don't have any problem to run it at all!
One thing strange is, when I directly debug the project in the client machine, I see no problem. Why do I get the error, when running the deployed project in the server?
HuaMin Chen
Rion William...
All-Star
26445 Points
4389 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 18, 2013 02:28 AM|LINK
The Connection String seems alright. The only thing that I could think that the deployed location isn't able to access the server hosting the database (your 192.168.168.1 address) or possibly some kind of permissions issue.
wmec
Contributor
6195 Points
3214 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 18, 2013 02:32 AM|LINK
But why don't I have any problem in other projects using the same connection string?
HuaMin Chen
wmec
Contributor
6195 Points
3214 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 19, 2013 02:57 AM|LINK
Dear all,
Any help to this?
HuaMin Chen
ToughMan
Participant
1490 Points
635 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 19, 2013 03:37 AM|LINK
Plz open VS and try to "View"=>"SQL Server Explorer" and create a connection to db and when successfully, plz copy the correct conn str.
wmec
Contributor
6195 Points
3214 Posts
Re: Format of the initialization string does not conform to specification starting at index 0
Feb 19, 2013 05:43 AM|LINK
Thanks. But I've shown the connection string which I am using inside the project, in my previous reply of this thread.
HuaMin Chen