locked
Error when viewing published listview/SqlDataSource but works perfectly in http://localhost:64509/etc... RRS feed

  • Question

  • User2094953549 posted

    Hello,

    I been breaking my head all day so hopefully someone can assist (I've tried looking for a solution online but to no avail) I simply created a basic DB in Visual Studio 2010 but I'm unable to view the data when the site is published, I get an error but it works perfectly when I right click on my solution > page > view in browser. I have no idea what I'm missing that's preventing it from viewing the results when the page has been published. I dragged a ListView & SqlDataSource to the page..

    The listView Data Source is: SqlDataSource1

    The DqlDataSource is: SalDataSource1

    This is the simple code:


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


    <head>

    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0 minimum-scale=1.0, maximum-scale=1.0,user-scalable=no, shrink-to-fit=no" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>Data</title>
    <meta name="Description" content="" />
    <meta name="Keywords" content="" />
    <meta name="apple-itunes-app" content="app-id=1034088603, affiliate-data=11l5aE" />

    </head>
    <body>

    <form id="form1" runat="server">
    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
    DataKeyNames="ID" DataSourceID="SqlDataSource1" Height="230px" Width="532px">
    <Columns>
    <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
    SortExpression="ID" />
    <asp:BoundField DataField="FirstName" HeaderText="FirstName"
    SortExpression="FirstName" />
    <asp:BoundField DataField="LastName" HeaderText="LastName"
    SortExpression="LastName" />
    <asp:BoundField DataField="Telephone" HeaderText="Telephone"
    SortExpression="Telephone" />
    <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
    </Columns>
    </asp:GridView>
    <p>
    It won&#39;t show!<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT * FROM [Table1]"></asp:SqlDataSource>
    </p>
    </form>

    </body>
    </html>

    Thursday, August 24, 2017 6:25 PM

All replies

  • User2103319870 posted

    I get an error

    Your code looks fine. If possible please provide more details about the error you are getting

    Thursday, August 24, 2017 8:53 PM
  • User-359936451 posted

    Its your connection string, it changes when you publish to a server. Post your connection string for your dev machine and the one you are using on your production machine in the web config file. Hide any password.

    Thursday, August 24, 2017 8:57 PM
  • User2094953549 posted

    It jumps to a generic 'oops.aspx' page I created so I'm unable to see the error. It simply won't connect to the data source while when I view in localhost, it shows all the data.

    Do I need imports or something on the listView.aspx.vb page? All I see in that page are:

    Option Explicit On
    Imports System.IO

    It's killing me as I feel it's something basic..

    This is the web.config:

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

    Thursday, August 24, 2017 8:58 PM
  • User2103319870 posted

    ;AttachDbFilename=|DataDirectory|\users.mdf;

    You are using LocalDB Connection String , check and ensure you have deployed the App_Data which contains the Users.mdf(database) file 

    Thursday, August 24, 2017 9:15 PM
  • User2094953549 posted

    The App_Data does have users.mdf>users_log.Ldf and it's included in the project so I'm assuming it deploys when I build>publish site.

    Am I missing something here?

    Thursday, August 24, 2017 9:19 PM
  • User2094953549 posted

    Now I went to Project > build deployment package and I got this error (I guess new errors is progressLaughing )

    Error 1 Web deployment task failed.(Object of type 'dbFullSql' and path 'Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\salamancac\Desktop\finance\App_Data\ContractUsers.mdf;Integrated Security=True;User Instance=True' cannot be created.)

    Object of type 'dbFullSql' and path 'Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\salamancac\Desktop\finance\App_Data\ContractUsers.mdf;Integrated Security=True;User Instance=True' cannot be created.
    Cannot connect to the database 'C:\Users\salamancac\Desktop\finance\App_Data\ContractUsers.mdf'.
    An attempt to attach an auto-named database for file C:\Users\salamancac\Desktop\finance\App_Data\ContractUsers.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. 0 0 Finance

    Thursday, August 24, 2017 9:22 PM
  • User1771544211 posted

    Hi nesbie,

    Error 1 Web deployment task failed.(Object of type 'dbFullSql' and path 'Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\salamancac\Desktop\finance\App_Data\ContractUsers.mdf;Integrated Security=True;User Instance=True' cannot be created.)

    It seems that the local database file ContractUsers.mdf can't be created. A high possible reason of this issue is that you don't have enough permission to write the mdf file to the location.

    Please try run your VS as administrator.

    Best Regards,

    Jean

    Friday, August 25, 2017 5:19 AM
  • User2094953549 posted

    Hi.

    The \ContractUsers.mdf;Integrated - was a database I first used and then deleted it, it can't create it cause it will never find ContractUsers.mdf - how can I change or update the log to replace/delete that old information and use the new one I created that's called users.mdf ? 

    Friday, August 25, 2017 2:02 PM
  • User1771544211 posted

    Hi nesbie,

    nesbie

    how can I change or update the log to replace/delete that old information and use the new one I created that's called users.mdf ? 

    Based on my understanding, there are two ways:

    1. Change the ContractUsers.mdf in the connection string to users.mdf and regenerate the database file.

    2. Use SQL Server Management Studio:

    • Open command prompt
    • Run SqlLocalDb infoto list currently installed LocalDb instances. There should be at least v11.0for Sql Server 2012/Visual Studio 2012 or MSSQLLocalDBfor Sql Server 2014/Visual Studio 2015
    • Open Sql Server Management Studio, or show Connect dialog if already running
    • Use Server name (localdb)\v11.0 or (localdb)\MSSQLLocalDB, whichever you're interested into. Select Windows Authentication
    • Create a new query
    • Paste the following template, adapting your path and names as needed:

      CREATE DATABASE __YourDbName__ ON (
        NAME='__YourDbName__', 
        FILENAME='YourDrive:\Your\path\to\data\files\__YourDbName__.mdf')
    • Run query

    • Refresh Object Explorer list of Databases

    Best Regards,

    Jean

    Monday, August 28, 2017 5:29 AM