I've written a sales and inventory program in C# that makes use of SQL Server, because I've heard it functions well over LAN connections (haven't tried it yet).
I've... let's say... hardwired the my connection string into the program. I have a notepad connection.ini file that has the connection string, which goes something like this:
Server=MY-PC\SQLEXPRESS;Database=dBaseAIS;Trusted_Connection=True;
So, everytime I have to connect to the SQL server, I use this:
string pathCheck = Directory.GetCurrentDirectory();
pathCheck = pathCheck.Replace(@"\", "/");
pathCheck = pathCheck.Replace(@"/bin/Debug", "/App_Data/connection.ini");
StreamReader sr = File.OpenText(pathCheck);
try
{
string sql = "DELETE FROM takeoffList;";
SqlConnection myConn = new SqlConnection(sr.ReadLine().ToString());
myConn.Open();
SqlCommand myComm = new SqlCommand(sql, myConn);
myComm.ExecuteNonQuery();
MessageBox.Show("Item has been deleted from database.", "AIS");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
The above code has no problems, whatsoever. The program works fine, but I needed Crystal Reports to finish it. So I tried to follow this page:
http://infynet.wordpress.com/2010/10/06/crystal-report-in-c/
Now, for some reason, that method requires a Data Connection (which up to this point, I assumed I had). When opening up Server Explorer in C#, the database is not there.
So I tried to create a new database via C# (Server Explorer), if only so I can see something in my Data Connections. Then it tells me "Name Pipes Provider, error 40 - Could not open a connection to SQL Server."
At this point, I have no idea what to do, or what happened (my program still runs fine).
I have Visual Studio 2005, Sql Management Studio Express (with TCP / IP and Name Pipes set to Enabled) and I'm running on Windows 7 32-bit (with sqlservr.exe and sqlbrowser.exe exceptions in the firewall).
Could anyone please tell me what I'm doing wrong? Thanks.