Click here to Skip to main content
16,009,391 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

I am working on WebApplication.In that I have created a method in datalayer by taking Datatable.For Datatable I have written the following code in SqlHelper.cs,

C#
public static DataTable ExecuteDataTable(string storedProcedureName,params SqlParameter[] arrParam)
  {
    DataTable dt = new DataTable();

    // Open the connection
    using (SqlConnection cnn = new SqlConnection("connectionString"))
    {
        cnn.Open();

        // Define the command
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Connection = cnn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = storedProcedureName;

            // Handle the parameters
            if (arrParam != null)
            {
                foreach (SqlParameter param in arrParam)
                    cmd.Parameters.Add(param);
            }

            // Define the data adapter and fill the dataset
            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
            {
                da.Fill(dt);
            }
        }
    }
    return dt;
  }


So when i am running this its shows the runtime error "Format of the initialization string does not conform to specification starting at index 0."
and
"using (SqlConnection cnn = new SqlConnection("connectionString"))"

I donot understand how to solve this..Anybody is there please help me.

Thanks..
Posted

1 solution

Look: the constructor of SQLConnection expects the connection string as a parameter.
And what do you do? You pass the word "coonectionString" to it, and that word is not a connection string!
Is there a variable with that name containing the connection string? if so, remove the quotation marks.
 
Share this answer
 
Comments
Shivani Dash 25-Apr-13 5:11am    
thanks for replying..I hv tried by moving quotation mark bt still its showing error line under ds.And if i'll put the exact connectionstring,then near DataSource its shows a red mark like ~ sign.so dnt understand wht to do.
Bernhard Hiller 25-Apr-13 5:26am    
show us the line where you set the connection string value, i.e. where you do a connectionString=...
Shivani Dash 25-Apr-13 6:18am    
using (SqlConnection cnn = new SqlConnection("Data Source=STPL/STPL; Initial Catalog=SBIFontManagement ; User ID=sa ; Password= Office123 ;"))
Bernhard Hiller 25-Apr-13 9:40am    
Data Source=STPL/STPL; looks bad. I'd expect a server=myserver\\myinstance; instead of it. Before taking a look at connectionstrings.com, you can try Data Source=STPL\\STPL;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900