0

すべてのデータ操作を保持し、を介してデータベースへの接続文字列を取得するSGDataLibraryクラスで呼び出されるクラスライブラリがあります。SGMemberDataOp.csapp.config

これが接続文字列です

 <add name="SimpleGym.Properties.Settings.SGYMConnectionString"
        connectionString="Data Source=owner\sqlexpress;Initial Catalog=SGYM;Integrated Security=True"
        providerName="System.Data.SqlClient" />

これはSGMemberDataOp.csクラスです

namespace SGDataLibrary
{
   public class SGMemberDataOp
   {
      private string connectionString = Properties.Settings.Default.SGYMConnectionString;

これが私のApp.xaml.csファイルに書いているコードです

 public partial class App : Application
 {
     ---->private static SGMemberDataOp sgMemberDataOp = new SGMemberDataOp();
     public static SGMemberDataOp SGMemberDataOp
     {
        get { return sgMemberDataOp; }
     }
 }

矢印の付いた行が例外をスローしています

オブジェクト参照がオブジェクト インスタンスに設定されていません

4

1 に答える 1

0

私はこれを行うコードを見ただけですが

private static SGMemberDataOp sgMemberDataOp;

 public static SGMemberDataOp SGMemberDataOp
 {
    get { return sgMemberDataOp; }
 }

public App()
{
    try
    {
        sgMemberDataOp = new SGMemberDataOp();
    }
    catch (Exception Ex)
    {
        MessageBox.Show(Ex.Message, "Startup failed", MessageBoxButton.OK);
    }
}

プライベートとしてそれを新しくすることはうまくいきませんでした、そして理由はわかりません。

于 2012-12-04T19:09:07.680 に答える