不支持关键字:'用户ID'。 [英] Keyword not supported : 'user id'.
问题描述
我正在使用此连接字符串,但每当我尝试连接数据库时出现错误不支持关键字:'用户ID'。
这是我的连接字符串:
I'm using this connection string but whenever I attempt to connect to the database an error "Keyword not supported: 'user id'."
Here's my connection string:
string connectionstring = @"user id=" + @txtServerUsername.Text + ";password=" + @txtServerPassword.Text + ";server=" + @txtServerName.Text + ";Trusted_Connection=yes;database=" + @txtDatabaseName.Text + ";connection timeout=30";
推荐答案
请参考此它可以帮助你 [ ^ ]
<connectionStrings>
<add name="EmployeeContext" connectionString="Data Source=SQLEXPRESS;Initial Catalog=Sample;User ID=ID Password=PWD;" providerName="System.Data.SqlClient" />
</connectionStrings>
在与数据库建立连接时,我收到此错误(使用实体框架)。在知道确切问题后,我删除了用户ID之间的空间并从数据库中获取详细信息,只需删除Userid之间的空格或定义用户ID并在连接字符串中正确使用Passward
While making a connection with the database I get this error (using entity framework). After knowing the exact problem, I removed the space between User ID and get the details from database, simply remove the space between the Userid or define your user id and Passward proper in a connection string
>
嗨佛罗里达州,
以下是在应用程序的cofig文件中创建连接字符串的标准方法。
Windows身份验证:
Hi Florida,
Followings are the standard ways to create connection string in the cofig file of the application.
Windows Authentication:
<connectionStrings>
<add name="connString" connectionString="Data Source=SPICITY1140\SQLEXPRESS;Initial Catalog=SPI_RFID2016;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
SQL Server身份验证:
SQL Server Authentication:
<connectionstrings>
<add name="connString" connectionstring="Data Source=MT000XBSQL107\INST2;Initial Catalog=SRA;Persist Security Info=True;User ID=SRA_SSIS;Password=password">
providerName="System.Data.SqlClient" />
</add></connectionstrings>
在C#中代码:
In C# code:
private string conStr = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;
Programmaticalyy:
Programmaticalyy:
private DbConnection CreateConnection(string connectionString)
{
return new SqlConnection(connectionString);
}
private string CreateConnectionString(string server, string databaseName, string userName, string password)
{
var builder = new SqlConnectionStringBuilder
{
DataSource = server, // server address
InitialCatalog = databaseName, // database name
IntegratedSecurity = false, // server auth(false)/win auth(true)
MultipleActiveResultSets = false, // activate/deactivate MARS
PersistSecurityInfo = true, // hide login credentials
UserID = userName, // user name
Password = password // password
};
return builder.ConnectionString;
}
如何使用:
How to Use:
public void ConnectoToDbWithEf6()
{
using(var connection = CreateConnection(CreateConnectionString("server", "db", "you", "password")
{
using(var context = new YourContext(connection, true))
{
foreach(var someEntity in context.SomeEntitySet)
{
Console.WriteLine(someEntity.ToString());
}
}
}
}
谢谢,
Prateek
Thanks,
Prateek
这篇关于不支持关键字:'用户ID'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!