SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TropicalConnectionString"].ConnectionString);
It said
Object reference not set to an instance of an object.
In order to check the error, I gave my app.config
, and I want to know is it possible I gave the wrong name for Initial Catalog etc?
Here is my 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>
Try this: