错误用户未与受信任的SQL连接相关联 [英] error user was not associated with trusted sql connection

查看:69
本文介绍了错误用户未与受信任的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

推荐答案

您的连接字符串错误,使用受信任的连接时您未指定用户名和密码

http://www.connectionstrings.com/sql-server-2005 [受信任的连接 [
Your connection string is wrong, you don''t specify user name and password when using a Trusted Connection

http://www.connectionstrings.com/sql-server-2005[^]

If you want to use a trusted connection[^], you need to make sure your windows account has sufficient permissions on the server

Follow the instructions for step ''A Windows account with insufficient permissions''


有时可以通过将身份验证下的sql服务器的安全模式设置为SQLServer和Windows来解决此问题.

希望对您有所帮助.
This can sometimes be fixed by setting the sql server''s security mode, under authentication, to SQLServer And Windows.

Hope this helps.


确保您具有正确的数据库连接字符串.

这样的事情.

Make sure you have the correct database connection string.

Something like this.

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


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

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