Dear Sir,
Referring to the first Sample program from chapter 14.
I have encountered this error "InvalidArgument=Value of "0" is not valid for 'SelectedIndex' during run the Sample program "Ch14createDatabase" -> Database management Subsystem > click on file > click on Select Server.
The error is captured from frmserverSelect.cs file as below.
private void btnServer_Click(object sender, EventArgs e)
{
short i;
cmbServer.SelectedIndex = 0; // Use the server they selected to list databases
serverToUse = cmbServer.SelectedItem.ToString();
string conn = "Data Source=" + serverToUse + "; Integrated Security=True;";
cmbDatabase.Visible = true;
lblDb.Visible = true;
try
{
using (SqlConnection sqlConn = new SqlConnection(conn))
{
sqlConn.Open();
DataTable tblDbs = sqlConn.GetSchema("Databases");
sqlConn.Close();
foreach (DataRow row in tblDbs.Rows)
{
i = (short)row.ItemArray[1];
if (i > SYSTEMDBTYPES)
cmbDatabase.Items.Add(row["database_name"].ToString());
}
}
cmbDatabase.SelectedIndex = 0;
error occur here....
} catch (SqlException ex)
{
MessageBox.Show("Error occurred while reading database data: " + ex.Message);
}
}
I have followed every steps from the book. From my understanding this code is used to display the available database on the machine(my PC). In my case, i think, it fail to list out the SQL server name...
By the way, is there any way to use C# to detect the available SQL server on the local PC?
Perhaps, you can advice what goes wrong the codes or the System configuration so that i can resolved.
My PC setup..
1.Installed Microsoft Visual Studio 2012.
2.Installed Microsoft SQL Server Developer
3.Created New rule for TCP port 1433.
Thanks ..
Regards,
ReGuy