You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Brian Elcock <br...@gmail.com> on 2008/11/12 07:09:06 UTC
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
Re: 答复: Sharing ConnectionStrings
Posted by Brian Elcock <br...@gmail.com>.
Thanks.
I recall seeing something like that in the list. I was hoping to do it
all through configuration. Is that not possible?
2008/11/12 smartkid <sk...@gmail.com>:
> 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:brian.elcock@gmail.com]
> 发送时间: 2008年11月12日 14:09
> 收件人: user-cs@ibatis.apache.org
> 主题: 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
答复: Sharing ConnectionStrings
Posted by smartkid <sk...@gmail.com>.
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:brian.elcock@gmail.com]
发送时间: 2008年11月12日 14:09
收件人: user-cs@ibatis.apache.org
主题: 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