SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TropicalConnectionString"].ConnectionString);
它说
对象引用未设置为对象的实例。
为了检查错误,我给了app.config
,我想知道是否有可能为初始目录等命名错误?
这是我的app.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="TropicalConnectionString"
connectionString="Data Source = JIRAN-PC; Initial Catalog = TropicalServer; Integrated Security = True"
providerName="System.Data.SqlClient" />
<add name="TropicalServiceWinApp.Properties.Settings.TropicalConnectionString"
connectionString="Data Source=JIRAN-PC;Initial Catalog=TropicalServer;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ITropicalService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:5483/TropicalService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITropicalService"
contract="TropicalServiceRef.ITropicalService" name="BasicHttpBinding_ITropicalService" />
</client>
</system.serviceModel>
</configuration>
答案 0 :(得分:0)
试试这个: