PagedDataSource / DataList Paging / SQLDataAdapter - help need with ConnectionString

Discussion in 'Site Programming, Development and Design' started by Charlie, Apr 7, 2010.

  1. I am a moderate beginner to web development. I am using Visual Web Developer 2008 Express, Visual Studio version 9.0 on a laptop with Vista Home Basic.

    I have been looking for a solution to page a datalist and was very pleased to find
    http://www.aspdotnetcodes.com/DataList_Dynamic_Paging_PagedDataSource.aspx
    because it appears less complicated than other paging techniques I have found and the results demonstrated look brilliant.

    This is the first time I have ever tried using C#.

    I got an exception at quite an early stage in the tutorial but persevered to the end of the lesson in the hope that I would find a solution to the exception. Unfortunately I cannot so I would be very grateful if anyone can help.

    The tutorial uses a Country database but I use my own database. Aside from that I have all the code from the tutorial placed in my pages and I think I have all the necessary things written at the top of the page -

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;

    There are no squiggly lines under any of my code.

    My error comes from line 4 of the below extract.

    1 private void BindGrid()
    2 {
    3 string sql = "SELECT [Title] FROM [TableSG1] ORDER BY [Title] DESC";
    4 SqlDataAdapter da = new SqlDataAdapter (sql,"ConnectionStrings:ConnectionString");
    5 DataTable dt = new DataTable();
    6 da.Fill(dt);

    The exception is "Format of the initialization string does not conform to specification starting at index 0"

    I copied my connection string from my default.aspx page after adding the datasource.
    (In the tutorial there was nothing said about adding the datasource but I decided that having the datasource was probable one of those things that goes without saying because it produced a connection string).
    I have tried using the connection string from the webconfig file but squiggly lines told me to forget that idea.

    I have searched online and have tried various possible remedies used for other similar problems but I do not have the experience to truly understand how to proceed.

    I have the pager stting on my disign page as it should be and think it is ready to use apart from this line of code not working and preventing debug.

    Please help
     
  2. Ray

    Ray

    How is your connection string setup?
     
  3. Hi Ray,

    As far as I know how to answer that question - I dragged a datalist onto the page and configuered a data source using the VWD Express smart tag. This is all re localhost browsing at present. The code is as follows:

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>
    <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>'> </asp:Label>
    </ItemTemplate>
    </asp:DataList>

    < <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT [Title] FROM [TableSG1] ORDER BY [Title] DESC">
    </asp:SqlDataSource>


    The web config connection string is as follows:

    <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MainDB1.mdf;Integrated Security=True;User Instance=True"
    providerName="System.Data.SqlClient" />
    </connectionStrings>

    That is all that I know I have done re connection string.
     
  4. Hi Ray,

    As far as I know how to answer that question - I dragged a datalist onto the page and configuered a data source using the VWD Express smart tag. This is all re localhost browsing at present. The code is as follows:

    <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>
    <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>'> </asp:Label>
    </ItemTemplate>
    </asp:DataList>

    < <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT [Title] FROM [TableSG1] ORDER BY [Title] DESC">
    </asp:SqlDataSource>


    The web config connection string is as follows:

    <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MainDB1.mdf;Integrated Security=True;User Instance=True"
    providerName="System.Data.SqlClient" />
    </connectionStrings>

    That is all that I know I have done re connection string.
     
  5. Ray

    Ray

    Try updating the connection string on your applications web.config file. As it stands right now you are trying to connect to a SQL Express database which we cannot support due to performance and security reasons.


    <add name="ConnectionString" connectionString="Data Source=DBServerName;Integrated Security=false;Initial Catalog=DBName;User ID=DBLogin;Password=DBPassword" providerName="System.Data.SqlClient" />

    As you can see this is an example and the values inside the connection string will have to be updated so that it is pointing to our SQL server and your database and that it is passing the correct db login and db password.
     
  6. Your advice was slightly at odds with my problem but none the less it was good advice. My problem was in debug in my local PC - hence I had not tried to load it to Winhost server. However your advice spurred me on to see if it would work on your server so I adjusted the connection string to my Winhost one and uploaded the page and got vague error with an added suggestion that I add a debug="true" to the top of the page to get more detail. I did that, reloaded and most excellently the connection string error is not mentioned.:)
    However, wouldn't ya know, there is another error. The good news is that it is on a line further down the page than the ConnectionString line so I think the original problem this post was about is solved.
    You may remember that it was recently noticed that Vista Home Basic ( which I am using ) does not support IIS7 - I wonder if that could mean that Home Basic cant support the assembler which was needed by the line of code this post began looking into which include sqldataAdapter - hence why it would not debug in my local pc??
    Anyway Thankyou for spurring me on :):) The new error is for another day - I will get there in the end ( I need a determined smiley)
     
    Last edited by a moderator: Oct 14, 2015

Share This Page