SQL 2005 connection failed
-
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
-
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
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();