Hi,

 

         You may use manual ISqlMapper construction.

 

         Step 1:             Declares a variable for the connectionString
attribute in SqlMap.config.

 

    <database>

        <provider name="sqlServer2.0"/>

        <dataSource name="Example"
connectionString="${IBatisNet.ConnectionString}"/>

    </database>

 

         Step 2:              Sets the value of the
${IBatisNet.ConnectionString} variable before createing the ISqlMapper
instance. 

 

       private static ISqlMapper CreateSqlMapper() {

           String connStr =
System.Configuration.ConfigurationManager.ConnectionStrings["CSNAME"];

            DomSqlMapBuilder builder = new DomSqlMapBuilder();

 

            NameValueCollection properties = new NameValueCollection();

            properties.Add("IBatisNet.ConnectionString", connStr);

            builder.Properties = properties;

 

            ISqlMapper result = builder.Configure("SqlMap.config");

            return result;

        }

 

yours

Yaojian

 

-----邮件原件-----
发件人: Brian Elcock [mailto:[EMAIL PROTECTED] 
发送时间: 2008年11月12日 14:09
收件人: [email protected]
主题: Sharing ConnectionStrings

 

Hello.

 

I've seen a few discussions surrounding this but haven't figured out

how to get it working in my own application. I would like to put my

connection string in a separate config file -- say security.config. I

am using both the ASP.NET membership provider and my own stuff via

iBATIS.NET. So I have my sqlMap.config file with the following:

 

         <database>

                   <provider name="sqlServer2.0" />

                   <dataSource name="DSName" connectionString="???" />

         </database>

 

Then my web.config has this:

 

<connectionStrings configSource="security.config"></connectionStrings>

 

security.config has this:

 

<connectionStrings>

         <add name="CSNAME" connectionString="initial catalog=ttt;data

source=ttt;User Id=uid;password=pwd;"/>

</connectionStrings>

 

I've tried a few different things with what to put in the

sqlMap.config file. The most common error I get is:

 

Format of the initialization string does not conform to specification

starting at index 0.

 

Can someone tell me what, specifically, I need to put in my

sqlMap.config file to get at the connection string called "CSNAME" ?

 

Thanks for your help.

 

I am using V 1.6.1.0 and ASP.NET 2.0.

 

Brian

Reply via email to