esteimle - Thursday, January 5, 2012 12:30 PM:
I've been searching the forums and so far have come up empty. I see a lot of people making oldb connections to access databases, but all of my part data is in another MS SQL database on the same MS SQL server as Aras.
Does anyone know the correct way to connect to that kind of database so I can run queries against it?
Thank you!
esteimle - Thursday, January 5, 2012 1:16 PM:
Well figured part of this out so thought I'd post for people who come after me. I was able to connect to the server, run a query, and return it as a part. Although I still have no idea how to return all of my parts in a grid or how to put them in the user interface. Anyway hope this helps someone.
System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection ();
// TODO: Modify the connection string and include any
// additional required properties for your database.
conn.ConnectionString =
"integrated security=SSPI;data source=my_server\sqlexpress;" +
"persist security info=False;initial catalog=CIP_E";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlDataReader reader;
Item res5 = this.newItem("Part");
string newid = getNewID();
res5.setID(newid);
// Call apply on the item to create it in the server. After this is done
// we can populate with the returned information from the external database
res5 = res5.apply();
try
{
conn.Open();
// Insert code to process data.
cmd.CommandText = "SELECT * FROM CAPACITORS";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
//sqlConnection1.Open();
reader = cmd.ExecuteReader();
res5.setProperty("part_number", reader["PART_NUMBER"].ToString());
}
catch (Exception ex)
{
//MessageBox.Show("Failed to connect to data source");
}
finally
{
conn.Close();
}
return res5;