Hello all,
This is a bit if a broad brush question but i'm hoping there is someone out there who has encountered a need for this as well.
I'm wondering whether some 'database' management code exists out there (for want of a better description!!). What I mean by this is I am looking for some code to allow me to select a server and then select a database. I am developing some code and part of it should allow users to select a database which the application subsequently uses. The idea is that the database can quickly and easily be changed.
I am hoping someone can perhaps offer some advise or links to something that already exists perhaps...I hate re-inventing the wheel when I don't have to!!
Thanks
Loading
Mahesh ChandPosted Oct 8, 2010, 1:20 PM
Sam HobbsPosted Oct 8, 2010, 1:16 PM
Sam HobbsPosted Oct 6, 2010, 5:37 AM
theLizardPosted Oct 6, 2010, 4:49 AM
This may help you, I use this in my controls.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel.Com2Interop;
namespace LizardControls
{
class NetServerNames
{
public const uint ERROR_SUCCESS = 0;
public const uint ERROR_MORE_DATA = 234;
[DllImport("netapi32.dll", EntryPoint = "NetServerEnum", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern int NetServerEnum(
[MarshalAs(UnmanagedType.LPWStr)]
string servername,
int level,
out IntPtr bufptr,
int prefmaxlen,
ref int entriesread,
ref int totalentries,
SV_101_TYPES servertype,
[MarshalAs(UnmanagedType.LPWStr)]
string domain,
int resume_handle);
[DllImport("netapi32.dll", EntryPoint = "NetApiBufferFree", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern int NetApiBufferFree(IntPtr buffer);
[StructLayout(LayoutKind.Sequential)]
public struct SERVER_INFO_101
{
[MarshalAs(UnmanagedType.U4)]
public PLATFORM_ID sv101_platform_id;
[MarshalAs(UnmanagedType.LPWStr)]
public string sv101_name;
[MarshalAs(UnmanagedType.U4)]
public uint sv101_version_major;
[MarshalAs(UnmanagedType.U4)]
public uint sv101_version_minor;
[MarshalAs(UnmanagedType.U4)]
public SV_101_TYPES sv101_type;
[MarshalAs(UnmanagedType.LPWStr)]
public string sv101_comment;
}
public enum SV_101_TYPES : uint
{
SV_TYPE_WORKSTATION = 0x00000001,
SV_TYPE_SERVER = 0x00000002,
SV_TYPE_SQLSERVER = 0x00000004,
SV_TYPE_DOMAIN_CTRL = 0x00000008,
SV_TYPE_DOMAIN_BAKCTRL = 0x00000010,
SV_TYPE_TIME_SOURCE = 0x00000020,
SV_TYPE_AFP = 0x00000040,
SV_TYPE_NOVELL = 0x00000080,
SV_TYPE_DOMAIN_MEMBER = 0x00000100,
SV_TYPE_PRINTQ_SERVER = 0x00000200,
SV_TYPE_DIALIN_SERVER = 0x00000400,
SV_TYPE_XENIX_SERVER = 0x00000800,
SV_TYPE_SERVER_UNIX = 0x00000800,
SV_TYPE_NT = 0x00001000,
SV_TYPE_WFW = 0x00002000,
SV_TYPE_SERVER_MFPN = 0x00004000,
SV_TYPE_SERVER_NT = 0x00008000,
SV_TYPE_POTENTIAL_BROWSER = 0x00010000,
SV_TYPE_BACKUP_BROWSER = 0x00020000,
SV_TYPE_MASTER_BROWSER = 0x00040000,
SV_TYPE_DOMAIN_MASTER = 0x00080000,
SV_TYPE_SERVER_OSF = 0x00100000,
SV_TYPE_SERVER_VMS = 0x00200000,
SV_TYPE_WINDOWS = 0x00400000,
SV_TYPE_DFS = 0x00800000,
SV_TYPE_CLUSTER_NT = 0x01000000,
SV_TYPE_TERMINALSERVER = 0x02000000,
SV_TYPE_CLUSTER_VS_NT = 0x04000000,
SV_TYPE_DCE = 0x10000000,
SV_TYPE_ALTERNATE_XPORT = 0x20000000,
SV_TYPE_LOCAL_LIST_ONLY = 0x40000000,
SV_TYPE_DOMAIN_ENUM = 0x80000000,
SV_TYPE_ALL = 0xFFFFFFFF
}
public enum PLATFORM_ID : uint
{
PLATFORM_ID_DOS = 300,
PLATFORM_ID_OS2 = 400,
PLATFORM_ID_NT = 500,
PLATFORM_ID_OSF = 600,
PLATFORM_ID_VMS = 700
}
//-----------------------------------------------------------------
public List
{
List
int read = 0;
int numServers = 0;
try{
do{
NetServerNames.SERVER_INFO_101 server;
IntPtr buffer;
int retVal = NetServerNames.NetServerEnum(
null,
101,
out buffer,
-1,
ref read, ref numServers,
NetServerNames.SV_101_TYPES.SV_TYPE_SQLSERVER,
null,
0);
if (retVal == NetServerNames.ERROR_SUCCESS
||retVal == NetServerNames.ERROR_MORE_DATA
|| read > 0){
int handle = buffer.ToInt32();
for (int i = 0; i < read; i++){
server = (NetServerNames.SERVER_INFO_101)Marshal.PtrToStructure(new IntPtr(handle),typeof(NetServerNames.SERVER_INFO_101));
handle += Marshal.SizeOf(server);
servers.Add(server.sv101_name);
}
}
NetServerNames.NetApiBufferFree(buffer);
}
while (read < numServers && read != 0);
}
catch(Exception e)
{
String s = e.Message;
}
return servers;
}
}
}
good luck..
Cos MarchyPosted Sep 29, 2010, 2:09 PM
I'll have a look at your suggestions and work from there.
Sam HobbsPosted Sep 28, 2010, 9:11 PM
Felipe RamosPosted Sep 28, 2010, 3:28 PM