Click here to Skip to main content
15,888,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What went wrong here?
C#
string connectionString = null;
            string sql = null;
            connectionString = "Server=(localdb)\v11.0;Integrated Security=true;";
            using(SqlConnection cnn = new SqlConnection(connectionString))
            {
                sql = "insert into EmailParser ([Sender]) values(@sender)";
                cnn.Open();
            using(SqlCommand cmd = new SqlCommand(sql, cnn))
            {
                cmd.Parameters.Add("@sender", SqlDbType.NVarChar, 50).Value = email.From;
                cmd.ExecuteNonQuery();
            }


What I have tried:

I don't know if it's the connectionString but my .mdf's data source is really long...
C#
Data Source=(LocalDB)\v11.0;AttachDbFilename="\\blah\USERS\blah\blah\My Documents\visual studio 2012\Projects\EmailParser\EmailParser\EmailParser.mdf";Integrated Security=True


I tried putting it after the connectionString but it's giving me an error.
What is the proper way of doing this?
Posted
Comments
Sascha Lefèvre 29-Mar-16 10:39am    
Did you look into the exception details / inner exception?
dumbasian 29-Mar-16 11:02am    
Here it is:

Additional information: 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)
ZurdoDev 29-Mar-16 11:11am    
Instead of (LocalDB) do (local) if you want to reference the local server. Or, better yet, just put in the name without the parenthesis.
Richard Deeming 29-Mar-16 11:41am    
Have you installed LocalDB? What results do you get if you run sqllocaldb info from a command prompt?
dumbasian 5-Apr-16 3:17am    
Already solved.

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



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