Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Excel to SQL

Excel to SQL

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadminregex
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MAW30
    wrote on last edited by
    #1

    I received the following error (see line *********error***********) when trying to transfer data from excel to sql using the code below. The sql table is in the database and columns all match the store procedure, does anyone have any idea what creates this problem. Thanks in advance, Michael Failed to obtain column collation information for the destination table. If the table is not in the current database the name must be qualified using the database name (e.g. [mydb]..[mytable](e.g. [mydb]..[mytable]); this also applies to temporary-tables (e.g. #mytable would be specified as tempdb..#mytable). void ExcelToSqlBulkCopy(String strPath, String strFile, String strTableName) { strExcelStoredProcedure = "SELECT ID,City,State FROM [Cities$]"; String excelConnectionString = y; String sqlConnectionString = z; // Create Connection to Excel Workbook using (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand(strExcelStoredProcedure, connection); connection.Open(); // Create DbDataReader to Data Worksheet using (DbDataReader dr = command.ExecuteReader()) { // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "[MyDatabase].[dbo].[" + strTableName + "]"; bulkCopy.WriteToServer(dr); *********error*********** } } connection.Close(); } }

    W H 2 Replies Last reply
    0
    • M MAW30

      I received the following error (see line *********error***********) when trying to transfer data from excel to sql using the code below. The sql table is in the database and columns all match the store procedure, does anyone have any idea what creates this problem. Thanks in advance, Michael Failed to obtain column collation information for the destination table. If the table is not in the current database the name must be qualified using the database name (e.g. [mydb]..[mytable](e.g. [mydb]..[mytable]); this also applies to temporary-tables (e.g. #mytable would be specified as tempdb..#mytable). void ExcelToSqlBulkCopy(String strPath, String strFile, String strTableName) { strExcelStoredProcedure = "SELECT ID,City,State FROM [Cities$]"; String excelConnectionString = y; String sqlConnectionString = z; // Create Connection to Excel Workbook using (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand(strExcelStoredProcedure, connection); connection.Open(); // Create DbDataReader to Data Worksheet using (DbDataReader dr = command.ExecuteReader()) { // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "[MyDatabase].[dbo].[" + strTableName + "]"; bulkCopy.WriteToServer(dr); *********error*********** } } connection.Close(); } }

      W Offline
      W Offline
      WoutL
      wrote on last edited by
      #2

      Does the table in strTableName exist in the database MyDatabase? And is dbo the owner of the table?

      Wout Louwers

      1 Reply Last reply
      0
      • M MAW30

        I received the following error (see line *********error***********) when trying to transfer data from excel to sql using the code below. The sql table is in the database and columns all match the store procedure, does anyone have any idea what creates this problem. Thanks in advance, Michael Failed to obtain column collation information for the destination table. If the table is not in the current database the name must be qualified using the database name (e.g. [mydb]..[mytable](e.g. [mydb]..[mytable]); this also applies to temporary-tables (e.g. #mytable would be specified as tempdb..#mytable). void ExcelToSqlBulkCopy(String strPath, String strFile, String strTableName) { strExcelStoredProcedure = "SELECT ID,City,State FROM [Cities$]"; String excelConnectionString = y; String sqlConnectionString = z; // Create Connection to Excel Workbook using (OleDbConnection connection = new OleDbConnection(excelConnectionString)) { OleDbCommand command = new OleDbCommand(strExcelStoredProcedure, connection); connection.Open(); // Create DbDataReader to Data Worksheet using (DbDataReader dr = command.ExecuteReader()) { // Bulk Copy to SQL Server using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString)) { bulkCopy.DestinationTableName = "[MyDatabase].[dbo].[" + strTableName + "]"; bulkCopy.WriteToServer(dr); *********error*********** } } connection.Close(); } }

        H Offline
        H Offline
        hans vogels
        wrote on last edited by
        #3

        bulkCopy.DestinationTableName = strTableName is sufficient, de database is in the sqlConnectionString

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups