MSDN Tikihut tour at Space Coast .Net

by Ken Tucker 7. November 2008 15:38
When:
Wednesday, November 19, 2008 6:30 PM Eastern Time (US & Canada)
   Who: Joe Healy, Jeff Barnes, and Russ Fustino

 

http://www.dotnettikihut.com/


Event Overview

 

Session 1 - What’s New in SQL Server 2008 for Developers - SQL Server 2008 adds numerous new capabilities for developers – from support for Spatial Data types to a storage mechanism for SQL BLOB data using the NTFS file system, and much, much more. The new release also delivers several improvements to development-related areas, from T-SQL to SQLCLR to XML. This presentation will provide a technical dive into the latest and greatest features you’ll find in SQL Server 2008, while offering insight into how to effectively apply them to your upcoming development projects.

 

Session 2 – Build next generation applications with Silverlight 2.0 - Silverlight provides a powerful platform for building the next generation of rich interactive applications on the Internet. In this session, we’ll take a look at the programming model and tools that developers and designers can leverage to build these true next generation experiences for consumers and business, and demonstrate how to build a rich interactive application (RIA) using Silverlight and Microsoft .NET. We’ll explore how to use Microsoft Visual Studio to create applications, and  networking, how to retrieve data from a Web service, and various other aspects of building Silverlight applications.

 

Session 3 – Real World Application - How to create an end-to-end Mobile GPS tracking application using the .NET Compact Framework, WCF, LINQ, Silverlight, Deep Zoom, and Virtual Earth - Inspired by a true-story mobility case study recently published on the Microsoft.com website, this session will walk you through how to create a mobile GPS tracking application using the .NET Compact Framework, Windows Mobile SDK, and Compact SQL.   At the Web host layer,   we will create a Windows Communication Foundation service and generate a Compact framework client proxy to send the GPS tracks to a host web server - where finally, the GPS trail can then be viewed using LINQ, Silverlight, Deep Zoom, and Virtual Earth.

 

Optional Session 4 (dependent on available event time) - Power up your Office applications with VSTO - In this presentation, we’ll focus on the power and productivity of Visual Studio Tools for the Microsoft Office System (VSTO) – a .NET Smart Client technology. We’ll give you tips and tricks for designing and building smart client applications with VSTO, which allows you to create managed code applications with .NET languages including Microsoft Visual Basic .NET and Visual C#. VSTO also makes it simple to manifest the functionality of those applications in the rich user interfaces of Microsoft Office Excel, Word, PowerPoint, Visio, Outlook and others from the Office stack. VSTO addresses some of the biggest challenges that Office solution developers are facing today, including separation of data and view elements, server-side and offline scenarios, seamless integration with the Visual Studio tools, deployment and updating. Join us for this eye-opening session and learn just how easy it is to build and deploy powerful applications with VSTO.

 

Please Register if you plan to attend this event.

https://msevents.microsoft.com/CUI/Register.aspx?culture=en-US&EventID=1032392616&CountryCode=US&IsRedirect=false



kick it on DotNetKicks.com

Sql Management Studio 2008 list database error

by Ken Tucker 29. October 2008 07:13

I have some sql 2005 databases I need to maintain on a web hosts sql server.  I was able to connect to the sql server fine with sql management studio 2008 but when I tried to expand the databases like I got an error like this.

 

 

 

image

 

I found this connect item which explains how to fix the issue

 

http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=354291

 

This seems to be similar to SSMS Object Explorer issue discussed here:
http://forums.microsoft.com/msdn/showpost.aspx?postid=3531315&isthread=false&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=0
Please try using the following workaround and let us know if that helps:
1) Bring Object Explorer Details window by selecting View --> Object Explorer Details in menu (or hitting F7)
2) In Object Explorer window click at Databases folder
3) In Object Explorer Details window right-click at the column header and deselect Collation
4) Refresh Databases folder.

 

 

Hope this helps

Uploading a Database to Dotster

by Ken Tucker 13. March 2008 04:17

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.

Sync Services Part 1

by Ken Tucker 26. January 2008 23:21

In this post we will create a local cache of the Northwind database.  To start with lets create a new visual basic windows forms project in Visual Studio 2008.  From the project menu select add a new item and select a new local database cache and name it northwind.

 

image

 

In the server connect select a connection to the northwind database.

 

Press the add button and select the product table.  Press OK to close the dialog.  Go ahead and create a table adapter for the product table.  The drag the products table on to the form from the data source window.  Add a button to the binding navigator and set its text to Sync and change the display style to Text.

 

In the button you added to the toolbar add this code

 

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

       ' Update the database

        Me.ProductsBindingSource.EndEdit()         Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet)

        ' Call SyncAgent.Synchronize() to initiate the synchronization process.

        ' Synchronization only updates the local database, not your project’s data source.

        Dim syncAgent As ProductsSyncAgent = New ProductsSyncAgent()         Dim syncStats As Microsoft.Synchronization.Data.SyncStatistics = syncAgent.Synchronize()

       ' Reload the data source from the local database

        Me.ProductsTableAdapter.Fill(Me.NorthwindDataSet.Products)

End Sub

Run the app and Open up the Sql Server Management Studio Express.  Make some changes in the Northwind database's Product table and Press the sync button.  

 

Notice the changes you made to the Products table show up in the datagridview.  The changes are also saved in the local sqlce database.



kick it on DotNetKicks.com

Sql Endpoint and DataGridView

by Ken Tucker 27. June 2007 07:12

Sql Endpoint and DataGridView

SQL Server 2005 allows you to create webservices for accessing the data in a database.  These webservices are call SQL End Points.  Lets start by creating a stored procedure to get the contact name and there titles for all the customers in the northwind database.  

Create PROCEDURE [dbo].[GetContacts]
AS
BEGIN
    SET NOCOUNT ON;

    SELECT [ContactName],[ContactTitle] FROM Customers ORDER BY [ContactName];
END

Now we can create the end point.  Note for this example I am using port 88 for the end point to prevent errors if you have IIS installed.

CREATE ENDPOINT NW_Contacts
    STATE = Started
AS HTTP
    (
        PATH = '/Contacts',
        AUTHENTICATION = (INTEGRATED),
        PORTS = (CLEAR),
CLEAR_PORT = 88,
        SITE = '*'
    )
FOR SOAP
    (
        WEBMETHOD 'GetContacts'
            (NAME = 'Northwind.dbo.GetContacts'),
        WSDL = DEFAULT,
        DATABASE = 'Northwind',
        NAMESPACE = DEFAULT
    )


Now we need to create a windows forms application.  I called the app EndPointTest.  On the form add a datagridview and set its dock property to fill.
Then add a web reference to the app.  For the url use http://localhost:88/contacts?WSDL.  For the name I used ContactEndPoint.
Here is some sample code for filling the datagridview with data from the end point

Imports System.Net

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ws As New ContactEndPoint.NW_Contacts

        ws.Credentials = CredentialCache.DefaultCredentials

        Dim ds As DataSet = TryCast(ws.GetContacts(0), DataSet)
        DataGridView1.DataSource = ds.Tables(0)

    End Sub
End Class

SMO: Connect to Remote Server

by Ken Tucker 10. March 2007 06:12

SMO: Connect to Remote Server



Here is a simple example on connecting to a Remote SQL Server with the SMO class. In this example I use a secure string for the password.



        Dim srv1 As New Server("ServerName")
        srv1.ConnectionContext.LoginSecure = False
        srv1.ConnectionContext.SecurePassword = GetSecureString("Password")
        srv1.ConnectionContext.Login = "UserName"

  Function GetSecureString(ByVal str As String) As Security.SecureString
        Dim ss As New System.Security.SecureString

        For Each c As Char In str.ToCharArray
            ss.AppendChar(c)
        Next

        ' prevent changes

        ss.MakeReadOnly()
        Return ss
    End Function

SQLCLR: Create a custom function

by Ken Tucker 13. February 2007 06:12

SQLCLR: Create a custom function



I store a persons full name in the name field of one my sql express database which I wanted to sort by the last name.  Well I could always try a query like this.

SELECT * FROM SPEAKERS ORDER BY SUBSTRING(NAME, PATINDEX('%  %', NAME), LEN(NAME) + 1 - PATINDEX('%  %', NAME))

Unfortuntely some of the names have a middle initial so this method was not fool proof.  This is where SQLCLR came to the rescue.  By creating a SQL Server Project you can create functions with VB.Net code.  So lets create a Sql Server Project and right click on the Project Name in the solution explorer.  Select Add-> User-Defined Function.    Once you add the code below you can use a query like this to sort by last name.

 

select * from Speakers order by dbo.LastWord(Name)

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

Partial Public Class UserDefinedFunctions
    <Microsoft.SqlServer.Server.SqlFunction()> _
    Public Shared Function LastWord(ByVal word As SqlString) As SqlString
        ' Add your code here
        Dim strWords() As String = word.ToString.Split(" "c)
        Return New SqlString(strWords(strWords.GetUpperBound(0)))
    End Function
End Class

SQL Server 2005 SP 1 help

by Ken Tucker 28. April 2006 04:12

SQL Server 2005 SP 1 help



From my partner Kelly Martins at KJM Solutions

If this error occurs here is what worked for me. I hope it may work for you but am not sure.


In my case I had SQL Express 2005 Installer on my system as well as I run both (one for development, one for production).



Shut down all SQL related services manually.

I set registry permissions on Software\Policies\Microsoft\Windows\Installer to include the account that is doing the install with Full Control. Click Advanced and make sure everything is selected.

I downloaded and ran the SQL Install Cleanup and removed the SQL 2005 Setup Files Installer and the SQL Express Installer. I then reinstalled the SQL Setup Files (ONLY!!!!!) from my SQL Server 2005 CD. If you don't don't do this you won't be able to use the SP.

Q290301 OFFXP: Windows Installer CleanUp Utility

I then reinstalled the SP and it worked

SQL Everywhere

by Ken Tucker 10. April 2006 17:42

SQL Everywhere



Microsoft will be removing the restrictions on sql sever 2005 mobile edition so it works in a desktop environment. Check out the SQL everywhere FAQ on Steve Lasker's blog


Sql Server 2005 Service Pack 1

by Ken Tucker 19. March 2006 17:42

Sql Server 2005 Service Pack 1



I see there is a CTP for a Sql Server 2005 service pack available. Here is a link for anyone interested.