|
Often I face problems while connecting Sql Server2005
|
|
|
|
|
No one sql server is enough on your PC. If you installed something like visual studio on your PC it will auto install sql express. Then if you installed sql server 2005 after you would have both on your box. I would remove sql express if you have sql server 2005 installed.
Ben
|
|
|
|
|
What problems are you having? I have been running both for a while now and have run into few problems. They are both treated as separate servers.
_____________________________________________________________________
Our developers never release
code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
Visit Me at GISDevCafe
|
|
|
|
|
Hi
I have one table Employee having fields id,Name,Salary (id is primary Key)
I have another table Phone having fields id,phone.(id is forign key)
1)using these two tables I want to get all the details of Employee who does not have phone Nos.
2)& I want details of all employees who have more than 2 phone nos.
Plz send these queries as soon as possible.
Thanks
Care Career
|
|
|
|
|
1)
Select e.* from employee e
left join Phone p on e.id = p.id
where p.id is null
2)
select e.id,p.phone from employee e
join phone p on e.id = p.id
group by e.id, p.phone
having count(*) > 1
You should probably buy a good sql book.
Ben
|
|
|
|
|
Hi,
In my app, I would like to insert data into MS Access. In my databse, have 3 columns-(datetime,datetime,text).Below is my code
strInsert = "INSERT INTO Alarms(Date,Time,description)VALUES ('"+dateTimePicker1.Value.Date+"', '"+dateTimePicker1.Value.Date+"' , 'err orlog')";
:
:
conx.open();
OleDbCommand cmd1 = new OleDbCommand(strInsert, conx);
cmd1.ExecuteNonQuery();
conx.close();
I am getting this error message - "OleDbException was unhandled". I am not idea what was wrong.Can anyone guide me to solve this error.
thanks in advance
cocoonwls
|
|
|
|
|
First you may want to figure out which line is cauing the error. If it is the conx.open() line then you have a problem with the connection. If it is the ExecuteNonQuery line then it is probably teh SQL. Is there more to teh error message? I've never inserted a datetime object before, but you may want to lookup the format it needs to be in and whether or not you need the single quotes around it.
Hope this helps.
--------------------------------------------------
Play Nation States and join The Code Project region with the password: byalmightybob
|
|
|
|
|
Hi,
Thanks for your reply.I have found the mistake.The Date value should put "#" symbol infront and after the variable, as below:
strInsert = "INSERT INTO Alarms (DateIn, TimeIn, Description) VALUES (#" +dateTimePicker1.Value+ "#,#" +dateTimePicker1.Value+ "#,'e')"
regards
cocoonwls
|
|
|
|
|
Hi
Select count(*) From TableName
Select count(column) From TableName
Select * From TableName
In these queries which will work more fast ? What could be the reason ?
|
|
|
|
|
DooDooo wrote: In these queries which will work more fast ?
Try them out to find out. Once you've run them, have a think about what each one is actually doing and how many rows they are returning. Hint - try the second count on a nullable column.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
DooDooo wrote: In these queries which will work more fast ? What could be the reason ?
They all do different things. It is an invalid comparison.
|
|
|
|
|
Ya I know all three queries are doing different things. What I mean to say was my friend told that select count(*) will take much time that executing select * from table. Because first it will select all data from table and finds the count. I just wanted to know whether this is rite or not ?
|
|
|
|
|
DooDooo wrote: What I mean to say was my friend told that select count(*) will take much time that executing select * from table. Because first it will select all data from table and finds the count. I just wanted to know whether this is rite or not ?
You also have to take in to consideration network bandwidth used. SELECT COUNT(*) FROM MyTable returns a single value. SELECT * FROM MyTable returns the entire contents of the table.
Also, I'd guess the COUNT(*) would be able to take into account an index so it wouldn't actually have to read every single row, just one of the indexes (which would be a lot less data)
|
|
|
|
|
|
Hi, All.
example: I have two databases. mySQL and MS SQL. I have to load some data from MySQL into MS SQL.
I can't use SSIS or something like that because my version of MS SQL Server hasn't it. so I must write my pwn programm foor this task.
I write two classes - first fro working with MySQL and second for MS SQL.
----------
MySQL
----------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
public class MySqlClass
{
public MySqlClass()
{
//
// TODO: Add constructor logic here
//
}
static public MySqlConnection myConnection = null;
public string GetConnection(string con_str)
{
string connection_string = string.Empty;
if (con_str.Length == 0)
connection_string = System.Configuration.ConfigurationManager.ConnectionStrings[2].ToString();
else
connection_string = con_str;
try
{
myConnection = new MySqlConnection(connection_string);
myConnection.Open();
}
catch (MySqlException err)
{
return "Erron in connection :" + err.Message;
}
finally
{
if (myConnection != null)
myConnection.Close();
}
return null;
}
public DataSet MySqlOpen(string sql_cmd)
{
if (myConnection != null)
myConnection.Close();
myConnection.Open();
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(sql_cmd, myConnection);
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet);
myConnection.Close();
return myDataSet;
}
public void MySqlRun(string sql_cmd)
{
if (myConnection != null)
myConnection.Close();
myConnection.Open();
MySqlCommand cmd = new MySqlCommand(sql_cmd, myConnection);
cmd.ExecuteNonQuery();
myConnection.Close();
}
public void MySqlRunTransaction(string[] queries)
{
MySqlTransaction trans = null;
if (myConnection != null)
myConnection.Close();
try
{
myConnection.Open();
trans = myConnection.BeginTransaction();
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = myConnection;
cmd.Transaction = trans;
foreach (string query in queries)
{
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
trans.Commit();
}
catch (MySqlException SqlErr)
{
if (trans != null)
{
trans.Rollback();
}
throw new Exception("An error occured while transaction", SqlErr);
//return;
}
finally
{
if (myConnection != null)
{
myConnection.Close();
}
}
}
}
----------
----------
MS SQL
----------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public class SqlClass
{
public SqlClass()
{
//
// TODO: Add constructor logic here
//
}
static public SqlConnection myConnection = null;
public string GetConnection(string con_str)
{
string connection_string = string.Empty;
if (con_str.Length == 0)
connection_string = System.Configuration.ConfigurationManager.ConnectionStrings[3].ToString();
else
connection_string = con_str;
try
{
myConnection = new SqlConnection(connection_string);
myConnection.Open();
}
catch (SqlException err)
{
return "Erron in connection :" + err.Message;
}
finally
{
if (myConnection != null)
myConnection.Close();
}
return null;
}
public DataSet SqlOpen(string sql_cmd)
{
if (myConnection != null)
myConnection.Close();
myConnection.Open();
SqlDataAdapter myDataAdapter = new SqlDataAdapter(sql_cmd, myConnection);
DataSet myDataSet = new DataSet();
myDataAdapter.Fill(myDataSet);
myConnection.Close();
return myDataSet;
}
public void SqlRun(string sql_cmd)
{
if (myConnection != null)
myConnection.Close();
myConnection.Open();
SqlCommand cmd = new SqlCommand(sql_cmd, myConnection);
cmd.ExecuteNonQuery();
myConnection.Close();
}
public void SqlRunTransaction(string[] queries)
{
SqlTransaction trans = null;
if (myConnection != null)
myConnection.Close();
try
{
myConnection.Open();
trans = myConnection.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Connection = myConnection;
cmd.Transaction = trans;
foreach (string query in queries)
{
cmd.CommandText = query;
cmd.ExecuteNonQuery();
}
trans.Commit();
}
catch (SqlException SqlErr)
{
if (trans != null)
{
trans.Rollback();
}
throw new Exception("An error occured while transaction", SqlErr);
//return;
}
finally
{
if (myConnection != null)
{
myConnection.Close();
}
}
}
}
----------
so in my main unit i declared them
public MySqlClass mys = new MySqlClass();
public SqlClass ms = new SqlClass();
and when I wanna get result from MySQL i do -
DataSet myDataSet = new DataSet();
try
{
myDataSet = mys.MySqlOpen(txtMySQLQuery.Text);
}
catch (MySqlException err)
{
Response.Write(err.ToString());
}
so I have a dataset with data (now myDataSet contains result of my query isn't ?)
my question - HOW can I load a data from this dataset into another database and table? i think I should use something like dataadapter or dataset but i'm not sure. and can I use ms.SqlRun for this (i declared it before) or I should use some another way?
thanx a lot!!!
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
tradakad wrote: I can't use SSIS or something like that because my version of MS SQL Server hasn't it.
SSIS is just a rebranded version of DTS. Use DTS.
|
|
|
|
|
I haven't got it too can i FREE download it? i mean for my MS SQL Server Express Edition version?
thanx!
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
I'm fairly sure that's not true, otherwise why would there be a separate download for the legacy DTS runtime? SSIS is effectively the next version of DTS (in development and Beta it was still called DTS and the process is called MsDtsServer.exe), but is not fully compatible with 2000's DTS.
Yes, if targetting SQL Server 2000 and optionally 2005, use DTS. Otherwise use SSIS.
SQL Server 2005 Express Edition doesn't have SSIS. That's only included in Standard and Enterprise Editions (and of course Developer Edition which is Enterprise with a restricted licence, the capability to run on client Windows operating systems, and autoshrink turned on). DTS was also not present in MSDE 2000.
|
|
|
|
|
Mike Dimmick wrote: I'm fairly sure that's not true, otherwise why would there be a separate download for the legacy DTS runtime?
It is a rebranded DTS. As you pointed out they rebranded it for SQL Server 2005 half way through the development cycle - hence there are references to DTS in the code.
Mike Dimmick wrote: SQL Server 2005 Express Edition doesn't have SSIS. That's only included in Standard and Enterprise Editions (and of course Developer Edition which is Enterprise with a restricted licence, the capability to run on client Windows operating systems, and autoshrink turned on). DTS was also not present in MSDE 2000.
True. I made an assumption that it was one of the full server or developer products that was being used.
|
|
|
|
|
HI all,
my application is to read a access dtbase tables which has the same format of columns. but it gives an update statement Syntax error. please help
OleDbConnection con = new OleDbConnection();
OleDbDataAdapter da = new OleDbDataAdapter();
OleDbCommand selcom = new OleDbCommand();
OleDbCommand upcom = new OleDbCommand();
DataSet ds = new DataSet();
private void button1_Click(object sender, EventArgs e)
{
string path = txtSelectLoc.Text;
processTables(path);
//UpdateMethod(path, "GRO");
}
void processTables(string path)
{
DataTable dt = new DataTable();
dt = sqlConnection().Tables[0];
foreach (DataRow dr in dt.Rows)
{
UpdateMethod(path,"WWA");
}
}
DataSet sqlConnection()
{
SqlCommand sqlSelect = new SqlCommand();
SqlConnection SQLcon = new SqlConnection("data source=Ruwandi;initial catalog=MIS;user id=sa");
SqlDataAdapter SQLda = new SqlDataAdapter();
sqlSelect.CommandText= "Select Alias from mfLocation where Alias<>''";
sqlSelect.Connection=SQLcon;
SQLda.SelectCommand = sqlSelect;
SQLda.Fill(ds);
return ds;
//dataGridView1.DataSource = ds.Tables[0];
}
private void UpdateMethod(string path,string tbName)
{
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path +
";Jet OLEDB:Database Password=sanuja";
DataTable dt = SelectMethod(tbName).Tables[0];
upcom.Connection = con;
con.Open();
int x = 0;
foreach (DataRow dr in dt.Rows)
{
x = x + 1;
string str = dr["CATEGORY"].ToString();
dr.AcceptChanges();
upcom.CommandText = "update CON_"+ tbName +" set BGT_APR=0,BGT_MAY=0,BGT_JUN=0,BGT_JUL=0,BGT_AUG=0,BGT_SEP=0,BGT_OCT=0,BGT_NOV=0,BGT_DEC=0,BGT_JAN=0,BGT_FEB=0,BGT_MAR=0,BUDGETED=0,BUDGET_PES=0," +
"NET_APR=0,NET_MAY=0,NET_JUN=0,NET_JUL=0,NET_AUG=0,NET_SEP=0,NET_OCT=0,NET_NOV=0,NET_DEC=0,NET_JAN=0,NET_FEB=0,NET_MAR=0," +
"LYNET_APR=" + dr["NET_APR"] + ",LYNET_MAY=" + dr["NET_MAY"] + ",LYNET_JUN=" + dr["NET_JUN"] + ",LYNET_JUL=" + dr["NET_JUL"] + ",LYNET_AUG=" + dr["NET_AUG"] + ",LYNET_SEP=" + dr["NET_SEP"] + ",LYNET_OCT=" + dr["NET_OCT"] + ",LYNET_NOV=" + dr["NET_NOV"] + ",LYNET_DEC=" + dr["NET_DEC"] + ",LYNET_JAN=" + dr["NET_JAN"] + ",LYNET_FEB=" + dr["NET_FEB"] + ",LYNET_MAR=" + dr["NET_MAR"] + "," +
"ADJ_APR=0,ADJ_MAY=0,ADJ_JUN=0,ADJ_JUL=0,ADJ_AUG=0,ADJ_SEP=0,ADJ_OCT=0,ADJ_NOV=0,ADJ_DEC=0,ADJ_JAN=0,ADJ_FEB=0,ADJ_MAR=0," +
"LYADJ_APR=" + dr["ADJ_APR"] + ",LYADJ_MAY=" + dr["ADJ_MAY"] + ",LYADJ_JUN=" + dr["ADJ_JUN"] + ",LYADJ_JUL=" + dr["ADJ_JUL"] + ",LYADJ_AUG=" + dr["ADJ_AUG"] + ",LYADJ_SEP=" + dr["ADJ_SEP"] + ",LYADJ_OCT=" + dr["ADJ_OCT"] + ",LYADJ_NOV=" + dr["ADJ_NOV"] + ",LYADJ_DEC=" + dr["ADJ_DEC"] + ",LYADJ_JAN=" + dr["ADJ_JAN"] + ",LYADJ_FEB=" + dr["ADJ_FEB"] + ",LYADJ_MAR=" + dr["ADJ_MAR"] +
" where CATEGORY=\'" + str + "\'";
da.UpdateCommand = upcom;
upcom.ExecuteNonQuery();
}
dt.AcceptChanges();
dataGridView1.DataSource = dt;
}
DataSet SelectMethod(string tbName)
{
selcom.CommandText = "select * from CON_"+tbName;
selcom.Connection = con;
da.SelectCommand = selcom;
da.Fill(ds);
return ds;
}
private void butSelectLoc_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
string path = openFileDialog1.FileName;
txtSelectLoc.Text = path;
}
}
regards
ruwandi
rkherath
|
|
|
|
|
|
hi,
thanks. I will do that.
regards
ruwandi
rkherath
|
|
|
|
|
Hi, ALL!
in MySQL I could execute this "show tables" and i got a list of tables in database. can I get a list of tables in a MS SQL database and how?
thanx!
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|
select * from INFORMATION_SCHEMA.TABLES
Gautham
|
|
|
|
|
Yep, i mean exactly this thing..
thank you, bro!
--
"Success is simple. Do what's right, the right way, at the right time."
best regards,
tradakad
|
|
|
|
|