VB with SQL R2 2008 Ex

Can any bode explain me In this code, where do I put SQL info ( Username and Password) to the Server ?

string connectionstring =  @"Data Source=sourcename;Initial Catalog=database;Integrated Security=True"; 
string query = "SELECT status FROM [table] WHERE username=@name and password=@pass";
//username and password are column names 
SqlConnection connection =  new SqlConnection(connectionstring); 
//pass the query to db 
SqlCommand command = new SqlCommand(query,connection); 
//pass the user name and password 
command.parameters.AddwithValue("@password",passwordtextboxvalue); 
command.parameters.AddWithValue("@username",usernametextboxvalue); 
try { 
    connection.Open(); 
    string status=command.ExecuteNonQuery(); 
    if(status==1) { 
        //unload and load } 
    else {
        //do something }  
} 
catch(Exception e) 
    { //handle the exception  }


October 12th, 2013 10:42am

Have a look at this thread:

How to Create a sql connection String in vb.net 2010

Free Windows Admin Tool Kit Click here and download it now
October 12th, 2013 10:52am

Looks like an account validation; it queries a table with a filter on user name and password (which is bad to store password!!). The user name and password have been entered in some input form and then passed with the variable "usernametextboxvalue" and "passwordtextboxvalue" to this code part. 
October 13th, 2013 11:21am

>>Integrated Security=True"

You use Windows Authentication which means SQL Server uses the credential of your (or user) windows account (loggin to Windows)

Free Windows Admin Tool Kit Click here and download it now
October 13th, 2013 11:24am

BTW, that's C# and not VB.NET.
October 13th, 2013 11:35am

Hi Avatar of BeAwareAlien

BeAwareAlien,

Is this still an issue ?

Free Windows Admin Tool Kit Click here and download it now
October 21st, 2013 3:07am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics