无法创建OLE DB提供程序“MSDASC”的实例。对于链接服务器“(null)” [英] Cannot create an instance of OLE DB provider "MSDASC" for linked server "(null)"

查看:138
本文介绍了无法创建OLE DB提供程序“MSDASC”的实例。对于链接服务器“(null)”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在开发一个应用程序,它将从用户那里获取excel文件并读取数据,最后它将把它存储在sql server 2008中。



但是当我尝试打开excel文件连接时它继续抛出上述错误。



这是我的代码:



Hi
I'm Developing an application which will get the excel file from the user and read the data and finally it will store it in sql server 2008.

But it keep on throwing the above error when i try to open a excel file connection.

Here is my code:

protected void btnSave_Click(object sender, EventArgs e)
        {
            string FileName = lblFileName.Text;

            string Extension = Path.GetExtension(FileName);

            string FolderPath = Server.MapPath(ConfigurationManager.AppSettings["FolderPath"]);

            string CommandText = "";

            switch (Extension)
            {

                case ".xls": //Excel 97-03

                    CommandText = "spx_ImportFromExcel03";

                    break;

                case ".xlsx": //Excel 07

                    CommandText = "spx_ImportFromExcel07";

                    break;

            }

            //Read Excel Sheet using Stored Procedure

            //And import the data into Database Table

            String strConnString = ConfigurationManager.ConnectionStrings["CARGONETConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = CommandText;
            cmd.Parameters.Add("@SheetName", SqlDbType.VarChar).Value = ddlSheets.SelectedItem.Text;
            cmd.Parameters.Add("@FilePath", SqlDbType.VarChar).Value =FolderPath + FileName;
            cmd.Parameters.Add("@HDR", SqlDbType.VarChar).Value =rbHDR.SelectedItem.Text;
            cmd.Parameters.Add("@TableName", SqlDbType.VarChar).Value = "TB_TransAgentSeaFreightRate";
            cmd.Connection = con;
            try
            {
                con.Open();
                object count = cmd.ExecuteNonQuery();
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Text = count.ToString() + " records inserted.";
            }

            catch (Exception ex)
            {

                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Text = ex.Message;

            }

            finally
            {

                con.Close();
                con.Dispose();
                Panel1.Visible = true;
                //Panel2.Visible = false;
                dg_AgentSFR.Visible = true;
            }
           
        }





任何人都可以帮助我。

在此先感谢。



Anyone please help me.
Thanks in advance.

推荐答案

My error was gone I run the below code:

USE [master] 
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1 
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1 
GO  


这篇关于无法创建OLE DB提供程序“MSDASC”的实例。对于链接服务器“(null)”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆