CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Mar 2007
    Posts
    69

    executing sp_databases from c#

    hi all,

    [EDIT] I am using sql server 2005

    i am having trouble executing the sp_databases stored procedure from my app... i am creating an sqlcommand and assigning the relevant value to their properties...

    one thing i have noticed is that if i use integrated security=true in the connectionstring it works no problem, however if i add a user to the master database with a password and try using the username and password from my application, it doesnt work!! can anyone explain why i cant execute sp_databases with sql authentication?

    here is my code so far
    Code:
    SqlCommand cmd = new SqlCommand();
     
    cmd.CommandText = "sp_databases";
     
    cmd.CommandType = CommandType.StoredProcedure;
     
    cmd.Connection = cf.masterCnn();
     
    ds = cf.getDbs(cmd);
     
    foreach (DataRow r in ds.Tables[0].Rows)
     
    {
     
    	 cboDatabase.Items.Add(r[0].ToString());
     
    }
     
    
    here is the connection creation:
    Code:
    public SqlConnection masterCnn() //this is responsible for instanciating the connection
     
    {
     
    master = masterString();
     
    cnn = new SqlConnection(master);
     
    return cnn;
     
    }
     
    
    Code:
    private string masterString()		 //this creates the connection string
     
    {
     
    string c;
     
    c = "server=" + server + ";initial catalog=master;Connect Timeout=10;user id=" + username + ";password=" + password + ";Trusted_connection=false";
     
    return c;
     
    }
     
    
    if anyone could shed some light on this, i would be really grateful

    thanks

    adam
    Last edited by Anti-Rich; June 19th, 2007 at 01:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured