
Sqlconnection(string) has some invalid arguments.

I get a tooltip error for SqlConnection sql = new SqlConnection(constring) SqlCommand comm = new SqlCommand("Insert into categories (categoryName) values ('" + tb_database.Text + "')", sql) SqlConnection sql = new SqlConnection(constring) rootwebconfig = .OpenWebConfiguration("/Mohtisham") protected void buttontb_click(object sender, EventArgs e) However I am not able to access the connection string in my code behind. I have specified the connection string to my NorthWind database in my web.config file.

In the near future, README file will cover connections to other kinds of servers and databases.I am learning to write into a database from a textbox with the click of a button. Command and Data Reader SqlCommand cmd = new SqlCommand() cmd.Connection = conn cmd.CommandType = CommandType.Text cmd.CommandText = "SELECT * FROM Person.Person" SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.Default) Stephen GlasskeysCįinally, close and dispose of the objects when finished.

This source creates a SQLcommand using the conn connection object created above. This is the connection string name, and we can use this to create a connection object in source: using System.Configuration //Retrieve Connection String By Name string sConn = "" ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings SqlConnection conn = new SqlConnection(settings.ConnectionString) Stephen GlasskeysĪlternatively, you can access the same setting value, reading the Application's properties: string sConnection = Stephen GlasskeysĪnd of course, the connection can be used to create SqlCommand or other data objects like a SqlDataReader. Notice the name=" " entry in the example image below. Look for values inside the connectionStrings tag. Next, open app.config to examine its contents. When the project is saved, Visual Studio updates setting information in the app.config XML file. However if everything works as it should, don't forget to click the Save toolbar icon to keep your new connection string setting. If you click Test Connection again and receive another error message, you may wish to read my piece on How to fix common SQL Server Management Studio 'Connect to Server' errors. To validate your connection, use the Test Connection feature, and click OK if you receive a "test connection succeeded" notification.īut.you may get an error message, which means you'll probably need to double-check the server name, log on credentials, or authentication entries.
