Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Guids
Message
From
24/06/2008 04:35:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Re: Guids
Environment versions
Environment:
C# 3.0
OS:
Vista
Database:
MS SQL Server
Miscellaneous
Thread ID:
01325529
Message ID:
01326281
Views:
18
>I think I figured it out. My Sql Server is on a remote server and fox is local so it maybe a network pathing thing.

Michael,
Then I'm afraid you'd go by datatable trick (I prefer to use reader but in this case you know:( ):
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;

class sbc
{
    static void Main(string[] args)
    {

        OleDbConnection source = new OleDbConnection(@"provider=vfpoledb;Data source=c:\temp\guids\guidtest.dbc");
        SqlConnection dest = new SqlConnection(@"server=.\sqlexpress;trusted_connection=yes;database=test;");

        DataTable tbl = new DataTable();

        dest.Open();

// Read with a false where to grab schema from SQL server - like set fmtonly on/off
        SqlCommand cmd = new SqlCommand("select * from GuidTest where 1=2", dest);
        SqlDataReader sRdr = cmd.ExecuteReader();
        tbl.Load(sRdr);

// Load from source into existing schema
        source.Open();
        OleDbCommand sourceCommand = new OleDbCommand(@"select * from " + args[0], source);
        OleDbDataReader dr = sourceCommand.ExecuteReader();
        tbl.Load(dr);
        source.Close();

        Console.WriteLine("Beginning Copy ....");

        try
        {
            using (SqlBulkCopy s = new SqlBulkCopy(dest))
            {
                s.BatchSize = 500;
                s.BulkCopyTimeout = 300;
                s.DestinationTableName = "GuidTest";
                s.NotifyAfter = 10;
                s.SqlRowsCopied += new SqlRowsCopiedEventHandler(s_SqlRowsCopied);
                s.WriteToServer(tbl);
                s.Close();
            }
            Console.WriteLine("Copy complete");
        }
        catch (Exception e)
        {
            Console.WriteLine("{0} Exception caught", e);
        }
        finally
        {
            dest.Close();
        }

    }

    static void s_SqlRowsCopied(object sender, SqlRowsCopiedEventArgs e)
    {
        Console.WriteLine("-- Copied {0} rows.", e.RowsCopied);
    }
}
It should be sligthly slower but still better than many other bulk loading options. I haven't tried timings on this.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform