Bagikan melalui


Fungsi LocalDBGetInstanceInfo

Mengembalikan informasi untuk instans SQL Server Express LocalDB yang ditentukan, seperti apakah ada, versi LocalDB yang digunakannya, apakah itu berjalan, dan sebagainya.

Informasi dikembalikan dalam structlocalDBInstanceInfo bernama, yang memiliki definisi berikut.

typedef struct _LocalDBInstanceInfo  
{  
      // Contains the size of the LocalDBInstanceInfo struct  
      DWORD  cbLocalDBInstanceInfoSize;  
  
      // Holds the instance name  
      TLocalDBInstanceNamewszInstanceName;  
  
      // TRUE if the instance files exist on disk, FALSE otherwise  
      BOOL   bExists;  
  
      // TRUE if the instance configuration registry is corrupted, FALSE otherwise  
      BOOLbConfigurationCorrupted;  
  
      // TRUE if the instance is running at the moment, FALSE otherwise  
      BOOL   bIsRunning;  
  
      // Holds the LocalDB version for the instance in the format: major.minor.build.revision  
      DWORD  dwMajor;  
      DWORD  dwMinor;  
      DWORD  dwBuild;  
      DWORD  dwRevision;  
  
      // Holds the date and time when the instance was started for the last time  
      FILETIME ftLastStartUTC;  
  
      // Holds the name of the TDS named pipe to connect to the instance  
      WCHARwszConnection;  
  
      // TRUE if the instance is shared, FALSE otherwise  
      BOOLbIsShared;  
  
      // Holds the shared name for the instance (if the instance is shared)  
      TLocalDBInstanceNamewszSharedInstanceName;  
  
      // Holds the SID of the instance owner (if the instance is shared)  
      WCHARwszOwnerSID;   
  
      // TRUE if the instance is Automatic, FALSE otherwise  
      BOOLbIsAutomatic;  
} LocalDBInstanceInfo;  
  

File header: sqlncli.h

Sintaksis

HRESULT LocalDBGetInstanceInfo(  
           PCWSTR wszInstanceName,  
           PLocalDBInstanceInfo pInstanceInfo,  
           DWORD dwInstanceInfoSize   
);  

Parameter-parameternya

wszInstanceName
[Input] Nama instans.

pInstanceInfo
[Output] Buffer untuk menyimpan informasi tentang instans LocalDB.

dwInstanceInfoSize
[Input] Menyimpan ukuran buffer InstanceInfo .

Pengembalian Barang

S_OK
Fungsi berhasil.

LOCALDB_ERROR_NOT_INSTALLED
SQL Server Express LocalDB tidak diinstal pada komputer.

LOCALDB_ERROR_INVALID_PARAMETER
Satu atau beberapa parameter input yang ditentukan tidak valid.

LOCALDB_ERROR_INVALID_INSTANCE_NAME
Nama instans yang ditentukan tidak valid.

LOCALDB_ERROR_UNKNOWN_INSTANCE
Instans tidak ada.

LOCALDB_ERROR_INSTANCE_FOLDER_PATH_TOO_LONG
Jalur tempat instans harus disimpan lebih panjang dari MAX_PATH.

LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_FOLDER
Folder instans tidak dapat diakses.

LOCALDB_ERROR_CANNOT_ACCESS_INSTANCE_REGISTRY
Registri instans tidak dapat diakses.

LOCALDB_ERROR_INSTANCE_CONFIGURATION_CORRUPT
Konfigurasi instans rusak.

LOCALDB_ERROR_INTERNAL_ERROR
Terjadi kesalahan tak terduga. Lihat log peristiwa untuk detailnya.

Detail lebih lanjut

Alasan di balik pengenalan struct argumen ukuran (lpInstanceInfoSize) adalah untuk memungkinkan API mengembalikan versi yang berbeda dari LocalDBInstanceInfostruct, secara efektif memungkinkan kompatibilitas maju dan mundur.

struct Jika argumen ukuran (lpInstanceInfoSize) cocok dengan ukuran versi LocalDBInstanceInfostruct yang diketahui, versi tersebut struct dikembalikan. Jika tidak, LOCALDB_ERROR_INVALID_PARAMETER dikembalikan.

Contoh umum penggunaan API LocalDBGetInstanceInfo terlihat seperti ini:

LocalDBInstanceInfo ii;  
LocalDBInstanceInfo(L"Test", &ii, sizeof(LocalDBInstanceInfo));  
  

Untuk sampel kode yang menggunakan API LocalDB, lihat Referensi SQL Server Express LocalDB.

Lihat Juga

Informasi Header dan Versi SQL Server Express LocalDB