Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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";
Posted
Updated 22-Jun-16 21:21pm
Comments
Rockstar_ 11-Jul-13 23:55pm    
Try with "uid" instead of "user id"
josephbhaskar 12-Jul-13 1:28am    
To connect to database, are you using native sql client or any 3rd party drivers?

Following is the connection string format I'm using in my project.

ConString="Server=10.60.1.25;Database=PinnacleDatabase;User Id=sa;Password=password123;"

Also try removing @ before connection string and check it.


If you are still getting the error, then post the complete error it will be helpful to resolve
Maciej Los 23-Jun-16 2:44am    
What database???

Hi Florida,
Followings are the standard ways to create connection string in the cofig file of the application.

Windows Authentication:

XML
<connectionStrings>
  <add name="connString" connectionString="Data Source=SPICITY1140\SQLEXPRESS;Initial Catalog=SPI_RFID2016;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>


SQL Server Authentication:
VB.NET
<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>


In C# code:
C#
private string conStr = ConfigurationManager.ConnectionStrings["connString"].ConnectionString;


Programmaticalyy:

C#
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:

C#
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());
            }
        }
    }

}



Thanks,
Prateek
 
Share this answer
 
Please refer this it amy help you[^]
 
Share this answer
 
XML
<connectionStrings>
  <add name="EmployeeContext" connectionString="Data Source=SQLEXPRESS;Initial Catalog=Sample;User ID=ID Password=PWD;" providerName="System.Data.SqlClient" />
</connectionStrings>


Quote:
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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900