如何导入Sqlbulk数据我在Con2.Open()获取错误 [英] How To I Import Sqlbulk Data Am Getting Error At Con2.Open()

查看:117
本文介绍了如何导入Sqlbulk数据我在Con2.Open()获取错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SqlConnection con1 = new SqlConnection("Data Source=aim-pc;Initial Catalog=ki;Integrated Security=True");
            SqlConnection con2 = new SqlConnection("Data Source=aim-pc;Initial Catalog=Integrated Security=True;");
            con2.Open();
            SqlCommand cmd = new SqlCommand("select * from txtfile", con2);
            SqlDataReader dr = cmd.ExecuteReader();
            SqlBulkCopy cc = new SqlBulkCopy("Data Source=aim-pc;Initial Catalog=ki;Integrated Security=True");
            cc.DestinationTableName = "txtfile";



我的数据库是ki,我的文件位置是e。

可以做什么

i想要详细说明而不是说这样做和那个


my database is ki and my file location is e.
what can be done
i want detail explanation not bit saying that do this and that

推荐答案

con2.open()

连接字符串不正确




我们无法解决这个问题!

我们不知道你应该连接什么字符串 - 它因系统而异,可能会涉及我们不同的用户ID和密码组合' - 并且不应该 - 知道......



尝试使用Server Explorer窗格在VS中建立连接:

1 )打开服务器资源管理器。

2)右键单击数据连接并选择添加连接

3)在随后的对话框中,选择您的数据源和数据库,指定安全信息,然后按测试连接按钮。

4 )当连接工作时,按确定

5)在服务器资源管理器窗格中突出显示数据库,然后查看属性窗格。将显示连接字符串的工作示例,您可以将其复制并粘贴到您的应用程序或配置文件中。
"con2.open()
not correct connection string"


We can't fix that!
We have no idea what you connection string should be - it varies from system to system, and will probably involve userID and password combinations that we don't - and shouldn't - know...

Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.


最好的学习方法是学习示例。看看这里: SqlBulkCopy类 [ ^ ]。在页面底部你会找到一个例子。



The best way to learn is to study on examples. Have a look here: SqlBulkCopy Class[^]. On the bottom of page you'll find an example.

Quote:

可以做什么

i想要详细说明而不是说这样做那个

what can be done
i want detail explanation not bit saying that do this and that



对不起,但你的问题形式不正确。我们无法帮助您,因为您没有提供有关您的问题的足够信息。我们无法读到您的想法,我们也看不到您的屏幕。



我们可以猜测您正在尝试从文本文件导入数据,但我们不能确定。我们对该文件中的数据结构一无所知。但是,我们可以提供一些有趣的链接,例如:

批量使用C#中的.net 2.0 SqlBulkCopy类导入文本文件 [ ^ ]

从Excel到SQL Server的Imoprt数据 [ ^ ]

SQL批量复制方法,用于向sql数据库中插入大量数据 [ ^ ]

将文本文件加载到SQL的最快方法 - SqlBulkCopy [ ^ ]



试试吧!祝你好运!


Sorry, but your question is not well-formed. We can't help you, because you did not provide enough information about your issue. We can't read in your mind and we have't see your screen.

We can guess that you're trying to import data from text file, but we can't be sure. We know nothing about the structure of data in that file. However, we can provide some interesting links, like:
Bulk import text files using .net 2.0 SqlBulkCopy class in C#[^]
Imoprt Data from Excel to SQL Server[^]
SQL Bulk copy method to insert large amount of data to the sql database[^]
Fastest Way to Load Text File To SQL – SqlBulkCopy[^]

Try! Good luck!


如错误所示,
Quote:

用户'目标登录失败-PC\aim'

,这意味着您没有在数据库连接字符串中指定任何用户凭据以建立与该数据库的连接。

因此,您的连接字符串必须包含数据库的用户名和密码。类似的东西,

connectionString =Server = .\SQLExpress; Database = TestDatabase; User ID = xyz; pwd = blah



如果您使用Windows身份验证连接到本地数据库,则需要设置 Trusted_Connection = True ;如果您使用的是SQL Server身份验证,则需要声明 User Id = myUsername;密码= MYPASSWORD ;在连接字符串中。



-KR

, that means that you have not specified any user credentials in your database connection string in order to make the connection to that database.
Therefore, your connection string must contain user name and password for the database. Something like,
connectionString="Server=.\SQLExpress;Database=TestDatabase;User ID=xyz;pwd=blah"

If you are using windows authentication to connect to the local DB, you need to set Trusted_Connection=True; if you are using SQL server authentication, you need to declare User Id=myUsername; Password=myPassword; in the connection string.

-KR


这篇关于如何导入Sqlbulk数据我在Con2.Open()获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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