Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SQL 2005 connection failed

SQL 2005 connection failed

Scheduled Pinned Locked Moved C#
databasehelpsysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    picasso2
    wrote on last edited by
    #1

    I have a SQL 2005 server using the following parameters DBName=MyDatabase user: joe123 passwrod:sm123 joe123 is teh MyDatabase owner I want to connect to the DB, find out the status and display it in textBox6. The problem is that the "try" block is not executed. Error with access deny. If I run c:\oslp -Ujoe123 -Psm123 -Slocalhost\SQLSRV--it works conStr ="user id=joe123;password=sm123;server=localhost\\SQLSRV;Trusted_Connection=yes;database=MyDatabase; connection timeout=30"; SqlConnection conn= new SqlConnection(conStr); try { conn.Open(); SqlCommand thisCommand = conn.CreateCommand(); thisCommand.CommandText = "SELECT DATABASEPROPERTYEX(‘ctxima’, ‘Status’) DatabaseStatus_DATABASEPROPERTYEX"; Object dbStatus = thisCommand.ExecuteScalar(); } catch (System.Exception excep) { MessageBox.Show(excep.Message); textBox6.Text=dbStatus } ANY HELP IS GREATLY APPRECIATED

    A 1 Reply Last reply
    0
    • P picasso2

      I have a SQL 2005 server using the following parameters DBName=MyDatabase user: joe123 passwrod:sm123 joe123 is teh MyDatabase owner I want to connect to the DB, find out the status and display it in textBox6. The problem is that the "try" block is not executed. Error with access deny. If I run c:\oslp -Ujoe123 -Psm123 -Slocalhost\SQLSRV--it works conStr ="user id=joe123;password=sm123;server=localhost\\SQLSRV;Trusted_Connection=yes;database=MyDatabase; connection timeout=30"; SqlConnection conn= new SqlConnection(conStr); try { conn.Open(); SqlCommand thisCommand = conn.CreateCommand(); thisCommand.CommandText = "SELECT DATABASEPROPERTYEX(‘ctxima’, ‘Status’) DatabaseStatus_DATABASEPROPERTYEX"; Object dbStatus = thisCommand.ExecuteScalar(); } catch (System.Exception excep) { MessageBox.Show(excep.Message); textBox6.Text=dbStatus } ANY HELP IS GREATLY APPRECIATED

      A Offline
      A Offline
      ammar_shaker
      wrote on last edited by
      #2

      Try to use an SqlDataSource from your toolbox, configure, custom a random select statement. SqlDataSource will automatically generate a connection string. use it as this example: MyConnection1.ConnectionString = SqlDataSource1.ConnectionString ; full example: SqlConnection con1 = new SqlConnection(); SqlCommand com1 = new SqlCommand(); con1.ConnectionString = SqlDataSource1.ConnectionString; <<<< con1.Open(); com1.Connection=con1; com1.CommandText="SELECT [Name] FROM Table1 WHERE [Id] = '"+TextBox1.Text.Trim()+"'"; com1.ExecuteNonQuery(); com1.Dispose(); con1.Close();

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups