本文介绍了错误用户未与受信任的SQL连接相关联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用sqlbulkcopy将数据从一个表复制到另一个表,但是我发现一个错误,因为用户未与受信任的sql连接相关联

我的代码是

i want to copy data from one table to another using sqlbulkcopy but i found an error as user was not associated with trusted sql connection

my code is

public static void PerformBulkCopy()
    {
        string connectionString = "Data Source=localhost;database=test;Trusted_Connection=true";

        {
            using (SqlConnection sourceConnection = new SqlConnection(connectionString))
            {
                SqlCommand myCommand = new SqlCommand("select * from odi", sourceConnection);
                sourceConnection.Open();
                SqlDataReader myReader = myCommand.ExecuteReader();

                using (SqlConnection destinationConnection = new SqlConnection(connectionString))
                {
                    destinationConnection.Open();

                    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection.ConnectionString))
                    {
                        bulkCopy.BatchSize = 50;
                        bulkCopy.NotifyAfter = 50;
                        bulkCopy.SqlRowsCopied += new SqlRowsCopiedEventHandler(bulkCopy_SqlRowsCopied);
                        bulkCopy.DestinationTableName = "odi1";
                        bulkCopy.WriteToServer(myReader);
                    }
                    destinationConnection.Close();
                }
                myReader.Close();
                sourceConnection.Close();
            }

        }
    }


请给我解决方案


give me the solution please

推荐答案



string connectionString = "Data Source=localhost;database=test;user id= xxxxxx; password = yyyyyy";


这篇关于错误用户未与受信任的SQL连接相关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 14:15