Demo of DotNet C# with SQL Server 2012 using a select statement

(Last Updated On: September 12, 2013)
Learn the Secret

Get  our 2 Free Books

Get these now which land directly to their inbox.
Invalid email address

Demo of DotNet C# with SQL Server 2012 using a select statement

Man this should have been easier.

msdn.microsoft.com/en-us/library/fksx3b4f.aspx

This connection string finally worked:

stackoverflow.com/questions/5558192/cannot-open-database-dbname-requested-by-the-login-the-login-failed-login-fa

Learn more about this SQL Server integration through FREE newsletter

C# Source code:

//social.msdn.microsoft.com/Forums/vstudio/en-US/feb96b4c-95fc-4a82-a5ab-81bf3b9a734e/sql-connection-string-window-authentication
//crtical SQL Server configuration www.linglom.com/it-support/enable-remote-connection-on-sql-server-2008-express/
using System;
using System.Data;
using System.Data.SqlClient;

namespace csbook.ch15 {

class Example15_3 {
static void Main(string[] args) {
//SqlConnection cs = new SqlConnection(“Data Source=I7-ACER-PC\\SQLEXPRESS; Initial Catalog=FinancialDemo; Integrated Security=SSPI; Persist Security Info=false; Trusted_Connection=Yes”);
// SqlConnection cs = new SqlConnection(“Server=localhost;Database=FinancialDemo;User Id=sa;Password=hello123;”);

//this one connects but user is not valid
//SqlConnection cs = new SqlConnection(“Server=localhost;Database=FinancialDemo;User Id=sa;Password=hello123;”);

//this seems to work finally
//stackoverflow.com/questions/5558192/cannot-open-database-dbname-requested-by-the-login-the-login-failed-login-fa
//refer to comment:
//If you change the connection string to have a sql server username and password that can be associated with the database then it will work if the application is not running under a windows identity that is not associated with sql server windows authentication

//SqlConnection cs = new SqlConnection(“Data Source=.\\SQLEXPRESS;Initial Catalog=FinancialDemo;Persist Security Info=True;User ID=sa;Password=hello123”);

//SqlConnection cs = new SqlConnection(“Data Source=sqlexpress;Initial Catalog=DashboardStorage;Persist Security Info=True;User ID=sa;Password=hello123”);

//conn.Open();
//cs.Open();
//System.Console.WriteLine(cs.State.ToString());
//cs.Close();

//msdn.microsoft.com/en-us/library/fksx3b4f.aspx
SqlConnection sqlConnection1 = new SqlConnection(“Data Source=.\\SQLEXPRESS;Initial Catalog=FinancialDemo;Persist Security Info=True;User ID=sa;Password=hello123”);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = “SELECT * FROM Tickers”;
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.

sqlConnection1.Close();
}
}
}

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!
This entry was posted in Featured, Quant Development and tagged , , , , on by .

About caustic

Hi i there My name is Bryan Downing. I am part of a company called QuantLabs.Net This is specifically a company with a high profile blog about technology, trading, financial, investment, quant, etc. It posts things on how to do job interviews with large companies like Morgan Stanley, Bloomberg, Citibank, and IBM. It also posts different unique tips and tricks on Java, C++, or C programming. It posts about different techniques in learning about Matlab and building models or strategies. There is a lot here if you are into venturing into the financial world like quant or technical analysis. It also discusses the future generation of trading and programming Specialties: C++, Java, C#, Matlab, quant, models, strategies, technical analysis, linux, windows P.S. I have been known to be the worst typist. Do not be offended by it as I like to bang stuff out and put priorty of what I do over typing. Maybe one day I can get a full time copy editor to help out. Do note I prefer videos as they are much easier to produce so check out my many video at youtube.com/quantlabs