Wayne Barron
asked on
C# Connection String to Access & SQL Server 2005
Hello All;
Learning ASP.NET.
OK. I have searched around and found a lot of code that is so compiled with a bunch of other code that it is hard for a newby to understand.
So, for this post, I am asking for the following.
#1: Connection String for Access Database (2000 & 2007)
#2: Connection String for SQL Server 2005
Basically like in ASP Classic where you can use this.
(Code below)
How would this be written for C# ASP.NET.
(I am using C#, as it is used in the Upload script that I am currectly using, so I am sticking with it for the moment)
Thank You
Carrzkiss
Learning ASP.NET.
OK. I have searched around and found a lot of code that is so compiled with a bunch of other code that it is hard for a newby to understand.
So, for this post, I am asking for the following.
#1: Connection String for Access Database (2000 & 2007)
#2: Connection String for SQL Server 2005
Basically like in ASP Classic where you can use this.
(Code below)
How would this be written for C# ASP.NET.
(I am using C#, as it is used in the Upload script that I am currectly using, so I am sticking with it for the moment)
Thank You
Carrzkiss
Set objConn = CreateObject("ADODB.Connection")
'objConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
'Server.MapPath ("database1.accdb") & ";"
objConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\InetPub\wwwroot\get\database1.accdb;Persist Security Info=False;"
objConn.Open
ASKER
I already know about these, and that is not what I asked for.
What I asked was the full thing in .NET C# Format.
What would this be in .NET C# Format
What I asked was the full thing in .NET C# Format.
What would this be in .NET C# Format
Set objConn = CreateObject("ADODB.Connection")
'objConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
'Server.MapPath ("database1.accdb") & ";"
objConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\InetPub\wwwroot\get\database1.accdb;Persist Security Info=False;"
objConn.Open
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Errors
CS0103: The name 'MessageBox' does not exist in the current context
I read where the MessageBox needed
using System.Windows.Forms;
But, then I got an error when trying to use it.
I changed it over to use
{
StatusLabel.Text = "Failed to connect. Reason" + System.Environment.NewLine + System.Environment.NewLine + e.Message;
}
Which of course run without issue, I am not a huge fan of MessageBoxes
That can get right annoying when something happens, A simple Textfield that shows that something has happened is better.
Complete code that works so far, if there is anything wrong with the way I have edited it, please let me know.
Carrzkiss
CS0103: The name 'MessageBox' does not exist in the current context
I read where the MessageBox needed
using System.Windows.Forms;
But, then I got an error when trying to use it.
I changed it over to use
{
StatusLabel.Text = "Failed to connect. Reason" + System.Environment.NewLine
}
Which of course run without issue, I am not a huge fan of MessageBoxes
That can get right annoying when something happens, A simple Textfield that shows that something has happened is better.
Complete code that works so far, if there is anything wrong with the way I have edited it, please let me know.
Carrzkiss
private void Page_Load(object sender, System.EventArgs ee)
{
string path = "G:\\InetPub\\wwwroot\\Testing\\NET\\1\\database1.accdb" ;
string cnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path + "';";
System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection(cnString);
try
{
cn.Open();
StatusLabel.Text = "Connection is open";
cn.Close();
}
catch (System.Exception e)
{
StatusLabel.Text = "Failed to connect. Reason" + System.Environment.NewLine + System.Environment.NewLine + e.Message;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://www.connectionstrings.com/
for Access:
http://www.connectionstrings.com/access-2007
http://www.connectionstrings.com/access
for SQL 2005
http://www.connectionstrings.com/sql-server-2005