I am very new to programming world (sorry if this question has been answered many times, at least i didnt get any clue from searching the internet), and i am trying to build a C sharp app recently. This exe will be called in another program, and upon calling, the program will pass a sql connection string value the c sharp exe app. My question is how to make the app receive the value.
the connection string should look like
“Provider=SQLOLEDB.1;Password=xxxxxxxx;Persist Security Info=True;User
ID=xxxxxxxx;Initial Catalog=ATTACH;Data Source=LNGSEAL136504A;
Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation
ID=LNGSEAL136504A;Use Encryption for Data=False;Tag with column collation when
possible=False”
What I wrote : Here is my code: class Program { static void Main(string[] args) { Console.WriteLine("its running!"); Console.ReadKey(); try {
int Len;
string cnn = null;
Len = args.Length;
for (int i = 0; i < args.Length; i++)
{
cnn = cnn + " " + args[i];
}
Console.WriteLine(cnn);
Console.WriteLine(Len);
Console.ReadKey();
ADODB.Connection mycnn = new ADODB.Connection();
mycnn.Open(cnn);
ADODB.Recordset rs = new ADODB.Recordset();
rs.Open("sql statements", mycnn);
mycnn.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
}
}
}
but it throws me a "unable to cast a com object error". Any idea? Please advise.
[Solved]
I used oledbconnection instead of adodb, and it works with no problem. Thanks for everyone who helped.