I am needing to pass username and password so that any user can run stored procedures on a database. In my web config I have my code set to this
<appSettings>
<add key="Connection1" value="server=validserver;database=validdatabase;uID=validuserid;password=validpassword;" />
</appSettings>
And in my C# - I first set a variable equal to the connection like so:
public const string MainDBConn = "Connection1";
and any time I want to use this connection string I call it like this
RunSQLQuery(MainDBCon, "nameofstoredprocedure");
However I keep getting this error thrown, which to me says it is an invalid conenction string, but my server name, database, userid and password are all valid...
Format of the initialization string does not conform to specification starting at index 0
What do I alter so that I can use this connection string in my syntax to connect to my server instance?
EDIT Altering my connection string to be
ConfigurationManager.ConnectionStrings["Connection1"].ConnectionString;
Now produces an error of:
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
EDIT 2
I modified my webconfig connection as suggested by @Khazratbek in his answer and now I get this error:
Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.
This could be because the pre-login handshake failed or the server was unable to respond back in time.
The duration spent while attempting to connect to this server was - [Pre-Login] initialization=3672; handshake=0;
That is strange to me as I have my timeout set to 0, which if I understand properly should set this to be non timeout
CommandTimeout = 0;