kreirao sam bazu i par tabela preko sqlcmd native client-a i napunio nekim podacima
Kad udjem u Visual Studio 2003, krieram u server exploreru lepo tu konekciju (pronadje i server i bazu) , ali mi se nikakve tabele ne pojavljuju u server explorer-u
Code:
private void button1_Click(object sender, System.EventArgs e) {
SqlConnection conn = new SqlConnection(
"workstation id=MY_SERVER;packet size=4096;integrated security=SSPI;data source=\"MY_SERVER\\SQLEXPRESS\";persist security info=False;initial catalog=IMENIK");
//@"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IMENIK;Data Source=MY_SERVER\SQLEXPRESS;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=MY_SERVER;Use Encryption for Data=False;Tag with column collation when possible=False");
SqlCommand comm = new SqlCommand(
"SELECT * FROM CITY", conn);
SqlDataReader rdr;
try{
conn.Open();
rdr = comm.ExecuteReader();
if (rdr.HasRows){
rdr.Read();
}
conn.Close();
}
catch(SqlException ex){
Console.Out.WriteLine("ERROR: " + ex.Message);
conn.Close();
}
}
private void button1_Click(object sender, System.EventArgs e) {
SqlConnection conn = new SqlConnection(
"workstation id=MY_SERVER;packet size=4096;integrated security=SSPI;data source=\"MY_SERVER\\SQLEXPRESS\";persist security info=False;initial catalog=IMENIK");
//@"Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IMENIK;Data Source=MY_SERVER\SQLEXPRESS;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=MY_SERVER;Use Encryption for Data=False;Tag with column collation when possible=False");
SqlCommand comm = new SqlCommand(
"SELECT * FROM CITY", conn);
SqlDataReader rdr;
try{
conn.Open();
rdr = comm.ExecuteReader();
if (rdr.HasRows){
rdr.Read();
}
conn.Close();
}
catch(SqlException ex){
Console.Out.WriteLine("ERROR: " + ex.Message);
conn.Close();
}
}
Kada koristim drugi Connection string gore (koji se prikaze u properties-ima od konekcije, onda pukne vec pri kreiranju konekcije i kaze (u exception-u):
Additional information: Keyword not supported: 'provider'.
(da li je to mozda u pitanju probem kombinacije VS2003 i SQL servera 2005 (express)?)
Kada koristim prvi string (kakav sam nasao po nekim knigama) onda uredno kreira konekciju i otvori je kako treba, ali pri ExecuteReader prijavljuje Exception sa Message-om:
Invalid object name 'CITY'.
U sqlcmd-u je sve ok:
Code:
1> select * from CITY
2> go
PTT Naziv
----------- ------------------------------
21000 Novi Sad
11000 Beograd
(2 rows affected)
1>
1> select * from CITY
2> go
PTT Naziv
----------- ------------------------------
21000 Novi Sad
11000 Beograd
(2 rows affected)
1>
She's nice from a far, but far from nice.