Click here to Skip to main content
13,664,842 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
wanted to connect the SQL database to C# using visual studio . When executed i'm getting an error

String source = "has the connection string "
SqlConnection con = new SqlConnection(source);
{
}

What I have tried:

tried all possible operations altering the source string
Posted 18-May-18 1:42am
Updated 18-May-18 2:22am
Comments
CHill60 18-May-18 8:01am
   
Can you confirm that the error is on
SqlConnection con = new SqlConnection(source);
or is it on some other line that you have not shared with us
CHill60 18-May-18 8:17am
   
Also can you remove any logon or password information from source and share it with us.
Richard MacCutchan 18-May-18 8:58am
   
"tried all possible operations altering the source string"
Did you try one that is actually a valid source? Because what you show above is just rubbish as far as SQL is concerned.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

For starters, you need to look at the exception itself - "Argument exception was unhandled" isn't the error, it's telling you that an error occurred and you didn't handle it.
So put a try ... catch block round the code, and use the debugger to look at exactly what the error is, including any InnerException data.

It's also worth double checking your code: that line doesn't normally throw any exceptions, it doesn't check the connection string until you Open the actual connection.

It's worth checking your connection string though - this may help: Simple SQL Connection String Creation[^]
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04-2016 | 2.8.180810.1 | Last Updated 18 May 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100