Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have to make connectionstring in C# winform config file.
in that I have server name="abc"
userid=root
and there is no password .

Please suggest.
Posted
Comments
[no name] 10-Apr-14 12:48pm    
www.connectionstrings.com

1 solution

I've pasted the code from how to do this that is available at the msdn page. For further reference have a look at the link at the bottom. Change the returning string at GetConnectionString() or replace it all together with a simple string. It's up to you and the situation you are facing.

C#
private static void OpenSqlConnection()
{
    //sets the connection string
    string connectionString = GetConnectionString();

    //makes sure the connetion will be disposed
    using (SqlConnection connection = new SqlConnection())
    {
        connection.ConnectionString = connectionString;

        connection.Open();

        Console.WriteLine("State: {0}\nConnectionString: {1};", connection.State, connection.ConnectionString);
    }
}

static private string GetConnectionString()
{
    // To avoid storing the connection string in your code,
    // you can retrieve it from a configuration file.
    return "Data Source=YourDataSource;Initial Catalog=yourCatalog;Integrated Security=true;";
}


Source: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx[^]

Regards
 
Share this answer
 

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