bburnett
Posts: 22
|
Posted: 09/03/2008, 1:58 PM |
|
I need a regular SqlConnection object because I need to do a stored proceedure with output parameters. I want to use the SQL Connection string for my existing CCS project connection.
I would have expected that the CCS Connection1DataAccessObject would support command that are Stored Proceedures with output parameters. And I would have thought C# would let me get the ConnectionString property of the Connection1DataAccessObject with something like:
Connection1DataAccessObject.ConnectionString
But neither appear to be true; this is the best approach that I've found (I'm I missing something?):
object o=Settings.Connection1DataAccessObject;
Type t = o.GetType();
System.Reflection.PropertyInfo pConnection = t.GetProperty("ConnectionString");
string strConnection = Convert.ToString(pConnection.GetValue(o, null));
strConnection = Regex.Replace(strConnection, "Provider=SQLOLEDB.1;", "");
SqlConnection conn = new System.Data.SqlClient.SqlConnection(strConnection);
_________________
Brandon Burnett
New Media Architect
REL Productions
West Des Moines, IA, USA
www.relonline.com |
|
|
Tuong Do
|
Posted: 09/03/2008, 6:01 PM |
|
I am not sure in C# but in VB .NET
I get the ConnectionString of a Connection1 as below
Dim ConnectionName as String = "Connection1"
Dim ConnectionString as String =
System.Configuration.ConfigurationSettings.AppSettings(Trim(ConnectionName)
& "String")
Response.write(ConnectionString)
"bburnett" <bburnett@forum.codecharge> wrote in message
news:848befa7f91a8e@news.codecharge.com...
>I need a regular SqlConnection object because I need to do a stored
>proceedure
> with output parameters. I want to use the SQL Connection string for my
> existing
> CCS project connection.
> I would have expected that the CCS Connection1DataAccessObject would
> support
> command that are Stored Proceedures with output parameters. And I would
> have
> thought C# would let me get the ConnectionString property of the
> Connection1DataAccessObject with something like:
> Connection1DataAccessObject.ConnectionString
>
> But neither appear to be true; this is the best approach that I've found
> (I'm I
> missing something?):
>
> object o=Settings.Connection1DataAccessObject;
> Type t = o.GetType();
> System.Reflection.PropertyInfo pConnection =
> t.GetProperty("ConnectionString");
> string strConnection = Convert.ToString(pConnection.GetValue(o, null));
> strConnection = Regex.Replace(strConnection, "Provider=SQLOLEDB.1;", "");
> SqlConnection conn = new
> System.Data.SqlClient.SqlConnection(strConnection);
> _________________
> Brandon Burnett
> New Media Architect
> REL Productions
> West Des Moines, IA, USA
> www.relonline.com
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
Tuong Do
|
Posted: 09/03/2008, 6:24 PM |
|
Or assume there is a Connection name "Connection1"
Dim cs as connectionstring = Settings.Connection1Connection
Response.write(cs.connection)
"bburnett" <bburnett@forum.codecharge> wrote in message
news:848befa7f91a8e@news.codecharge.com...
>I need a regular SqlConnection object because I need to do a stored
>proceedure
> with output parameters. I want to use the SQL Connection string for my
> existing
> CCS project connection.
> I would have expected that the CCS Connection1DataAccessObject would
> support
> command that are Stored Proceedures with output parameters. And I would
> have
> thought C# would let me get the ConnectionString property of the
> Connection1DataAccessObject with something like:
> Connection1DataAccessObject.ConnectionString
>
> But neither appear to be true; this is the best approach that I've found
> (I'm I
> missing something?):
>
> object o=Settings.Connection1DataAccessObject;
> Type t = o.GetType();
> System.Reflection.PropertyInfo pConnection =
> t.GetProperty("ConnectionString");
> string strConnection = Convert.ToString(pConnection.GetValue(o, null));
> strConnection = Regex.Replace(strConnection, "Provider=SQLOLEDB.1;", "");
> SqlConnection conn = new
> System.Data.SqlClient.SqlConnection(strConnection);
> _________________
> Brandon Burnett
> New Media Architect
> REL Productions
> West Des Moines, IA, USA
> www.relonline.com
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
dragoon
Posts: 173
|
Posted: 09/29/2008, 1:31 AM |
|
Quote Tuong Do:
Or assume there is a Connection name "Connection1"
Dim cs as connectionstring = Settings.Connection1Connection
Response.write(cs.connection)
string strConn = System.Configuration.ConfigurationManager.AppSettings["Connection1String"].Substring(System.Configuration.ConfigurationManager.AppSettings["Connection1String"].IndexOf(";"));
where Connection1 is the name of the connection to the db.
|
|
|
|