Locations of visitors to this page


Onteora Software - Asp

Onteora Software

Ken Tucker's Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent posts

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Uploading a Database to Dotster

The easiest way to upload a database to dotster is to use the sql hosting toolkit.   Visual studio 2008 installs the sql hosting toolkit for you otherwise you need to download and install from the link. 

 

Steps to do this

1) Create a database in the dotster control panel.

2) In the server explorer create a link to the database you want to upload. 

3) Right click on the database and select publish to provider in the wizard make sure you select sql 2000 as the target database schema.

4) On the codeplex website they use to have a webpage available to use to help run the script to create your database.  Now they have a webservice for this.   I kind of think the webservice is over kill to just publish 1 database.  So create a c# website which targets the .net framework 2.0

5) Add the script file you created in step 3 to the website.

6) Add the following code to webpage

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Web;
using System.IO;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace WebApplication3
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string fileName = Server.MapPath(@"<<YOUR_SCRIPTFILE>>.SQL");

            // Connection string to the server you want to execute against
            string connectionString = @"Server=<<YOUR_SERVER>>;User ID=<<YOUR_USERNAME>>;Password=<<YOUR_PASSWORD>>;Initial Catalog=<<YOUR_DATABASE>>";

            // Timeout of batches (in seconds)
            int timeout = 600;

            SqlConnection conn = null;
            try
            {
                Response.Write(String.Format("Opening file {0}<BR>", fileName));

                // read file
                using (StreamReader sr = new StreamReader(new FileStream(fileName, FileMode.Open)))
                {
                    Response.Write("Connecting to SQL Server database...<BR>");

                    // Create new connection to database
                    conn = new SqlConnection(connectionString);

                    conn.Open();

                    while (!sr.EndOfStream)
                    {
                        StringBuilder sb = new StringBuilder();
                        SqlCommand cmd = conn.CreateCommand();

                        while (!sr.EndOfStream)
                        {
                            string s = sr.ReadLine();
                            if (s != null && s.ToUpper().Trim().Equals("GO"))
                            {
                                break;
                            }

                            sb.AppendLine(s);
                        }

                        // Execute T-SQL against the target database
                        try
                        {
                            cmd.CommandText = sb.ToString();
                            cmd.CommandTimeout = timeout;

                            cmd.ExecuteNonQuery();

                        }
                        catch (Exception ex)
                        {
                            Response.Write(sb.ToString().Replace("\n", @"<br/>"));
                            Response.Write(ex.Message.ToString() + @"<br />");
                        }
                    }

                }
                Response.Write("T-SQL file executed successfully");
            }
            catch (Exception ex)
            {
                Response.Write(String.Format("An error occured: {0}", ex.ToString()));
            }
            finally
            {
                // Close out the connection
                //
                if (conn != null)
                {
                    try
                    {
                        conn.Close();
                        conn.Dispose();
                    }
                    catch (Exception e1)
                    {
                        Response.Write(String.Format(@"Could not close the connection.  Error was {0}", e1.ToString()));
                    }
                }
            }

        }
    }
}

 

Uploasd the website to dotster and open the webpage and your database should be copied to the new database.  Make sure you delete the website after you created the database to prevent someone from accidently undo changes to the database after you uploaded it.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Asp | C# | Sql
Posted by Ken Tucker on Wednesday, March 12, 2008 10:17 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Using XLinq to get a list of Photos from Spaces.Live.com

Using XLinq to get a list of Photos from Spaces.Live.com


Storing photo albums on line is becoming very popular. Spaces.Live.com photo is one place to store albums which exposes its photo albums via an rss feed. I thought it would be nice to test out Visual Studio 2008 XLinq by getting a list of Photo's from the Tampa Code Camp and display them in WPF Listbox.


The photos I am looking for can be found here.

http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/feed.rss

The xml in the rss feed exposes each photo like this

    <item>
      <title>volunteers arrived at 630am - nikita polyakov [mvp] led them</title>
      <link>http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/cns!75364D9E73295107!134</link>
      <description><p><a href="http://thedevfish.spaces.live.com&#47;photos&#47;cns&#33;75364D9E73295107&#33;133&#47;cns&#33;75364D9E73295107&#33;134" mce_href="http://thedevfish.spaces.live.com&#47;photos&#47;cns&#33;75364D9E73295107&#33;133&#47;cns&#33;75364D9E73295107&#33;134"><img src="http://storage.live.com&#47;items&#47;75364D9E73295107&#33;134&#58;thumbnail" mce_src="http://storage.live.com&#47;items&#47;75364D9E73295107&#33;134&#58;thumbnail" border="0"></a></p><p>volunteers arrived at 630am - nikita polyakov &#91;mvp&#93; led them</p><img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=8446023494112203015&page=RSS%3a+volunteers+arrived+at+630am+-+nikita+polyakov+%5bmvp%5d+led+them&referrer=" mce_src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=8446023494112203015&page=RSS%3a+volunteers+arrived+at+630am+-+nikita+polyakov+%5bmvp%5d+led+them&referrer=" width="1px" height="1px" border="0" alt=""><img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;NA=1149&amp;PI=73329&amp;RF=&amp;DI=3919&amp;PS=85545&amp;TP=thedevfish.spaces.live.com&amp;GT1=thedevfish" mce_src="http://c.live.com/c.gif?NC=31263&amp;NA=1149&amp;PI=73329&amp;RF=&amp;DI=3919&amp;PS=85545&amp;TP=thedevfish.spaces.live.com&amp;GT1=thedevfish"></description>
      <comments>http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/</comments>
      <guid isPermaLink="false">cns!75364D9E73295107!134</guid>
      <pubDate>Tue, 24 Jul 2007 18:24:10 GMT</pubDate>
      <slash:comments>0</slash:comments>
      <msn:type>photo</msn:type>
      <live:type>photo</live:type>
      <live:typelabel>Photo</live:typelabel>
      <wfw:commentRss>http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/cns!75364D9E73295107!134/feed.rss</wfw:commentRss>
      <wfw:comment>http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/cns!75364D9E73295107!134</wfw:comment>
      <dcterms:modified>2007-07-24T18:24:10Z</dcterms:modified>
      <enclosure type="image/jpeg" url="http://storage.live.com/items/75364D9E73295107!134" />
    </item>


Lets query the xml feed and get the title for the photo and convert the quid to a link for the photo. The link is http://storage.live.com/items/PictureId. The guid gives us cns!pictureId so we need to replace cns! with http://storage.live.com/items/



Class Window1

    Private Sub Window1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Dim strUrl As String = "http://thedevfish.spaces.live.com/photos/cns!75364D9E73295107!133/feed.rss "
        Dim feeds = XElement.Load(strUrl)

        Dim query = From p In feeds.Element("channel").Elements("item") _
                  Select title = p.Element("title").Value, link = p.Element("guid").Value.ToString.Replace("cns!", "http://storage.live.com/items/")

        lstPhotos.ItemsSource = query.ToList
    End Sub
End Class

Pages XAML

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:CodeCampPhotos"
    Title="Window1" Height="300" Width="300">
    <Grid>
<DockPanel>
<ListBox Name="lstPhotos" DockPanel.Dock="Top">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=title}" FontSize="10" />
<Image Source="{Binding Path = link}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Grid>
</Window>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Asp | Linq
Posted by Ken Tucker on Thursday, August 09, 2007 10:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Nested GridViews

Nested GridViews



In this example we are going to display the orders and its details from the Northwind database in one GridView.  In an TemplateField place a GridView which calls a function to get the child records.



The Web Page

 

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:GridView ID="GridView1" runat="server" CellPadding="4" GridLines="None"
                AutoGenerateColumns="False" ForeColor="#333333">
                <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:BoundField DataField="OrderId" HeaderText="Order ID" />
                    <asp:TemplateField HeaderText="Order Info">
                        <ItemTemplate>
                            <span>Customer </span>
                            <asp:Label ID="lblCust" Text='<%# Eval("CustomerID") %>' runat="server" /><br />
                            <span>Order Date </span>
                            <asp:Label ID="lblOrdDate" Text='<%# Convert.ToDateTime(Eval("OrderDate")).ToShortDateString %>'
                                runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Ordered Items">
                        <ItemTemplate>
                            <asp:GridView runat="server" ID="Details" DataSource='<%# GetDetails(Eval("OrderID")) %>'>
                                <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
                                <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
                                <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
                                <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
                                <AlternatingRowStyle BackColor="#DCDCDC" />
                            </asp:GridView>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EditRowStyle BackColor="#999999" />
            </asp:GridView>
        </div>
    </form>
</body>
</html>

 

The Code Behind File

 

Imports System.Data.SqlClient
Imports System.Data

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim dtDetails As New DataTable

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            Dim dt As New DataTable
            Dim strConn As String
            Dim da As SqlDataAdapter
            Dim conn As SqlConnection

            strConn = "Server = .\sqlexpress;Database = NorthWind; Integrated Security = SSPI;"
            conn = New SqlConnection(strConn)

            da = New SqlDataAdapter("Select * from Orders", conn)
            da.Fill(dt)
            da = New SqlDataAdapter("Select * from [Order Details]", conn)
            da.Fill(dtDetails)
            GridView1.DataSource = dt
            GridView1.DataBind()
        End If

    End Sub

    Public Function GetDetails(ByVal strID As String) As DataTable
        Dim dt As DataTable = dtDetails.Clone
        For Each dr As DataRow In dtDetails.Select("OrderID = " & strID)
            dt.ImportRow(dr)
        Next
        Return dt
    End Function
End Class

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Asp | VB
Posted by Ken Tucker on Friday, March 16, 2007 10:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed