I want to open a database from server using a connection string. I study using WebMatrix cshtml.

This is my simple code :

var db2 = Database.OpenConnectionString("IntegratedConnectionString");
var countUser = db2.QuerySingle("SELECT COUNT(*) FROM [User]");

and this is my connection string (fake one) :

<connectionStrings>
    <add name="IntegratedConnectionString" 
         connectionString="Data Source=lalala.cloudapp.net;Initial Catalog=Integrated;Persist Security Info=True;User ID=lalaladb;Password=lalala;MultipleActiveResultSets=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

and this is error that I get :

Format of the initialization string does not conform to specification starting at index 0.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Source Error:

Line 14: var confirmPassword = "";
Line 15: var db2 = Database.OpenConnectionString("IntegratedConnectionString");
Line 16: var countUser = db2.QuerySingle("SELECT COUNT(*) FROM [User]");
Line 17: // Setup validation
Line 18:

Please help me how to get data from SQL Server using WebMatrix cshtml.

Related posts

Recent Viewed