Anyone know how I can aquire my database connection string?

My professor taught me a way like so:

[IMG]http://i40.tinypic.com/2v154cm.jpg[/IMG]

[IMG]http://i41.tinypic.com/1059tvr.jpg[/IMG]

[IMG]http://i39.tinypic.com/2le3sly.jpg[/IMG]

[IMG]http://i42.tinypic.com/2eoy2qa.jpg[/IMG]


However after click the new connection button the window that is supposed to open doesn't open. I don't know what's wrong. Is there any other way to obtain the connection string?

Recommended Answers

All 6 Replies

Please, I know someone here has to know something about this subject.

Only 30 characters between me and my finished program! I have everything else already made, I just need that darn connection string. :P

Please help me guys.

Drop a table adapter on the form and it will pop the wizard up to create a connection string. Once you have created the connection string and saved it, you can access it in Properties.Settings.Default.ConnectionStringName

OR

You could manually make the connection string, see:
www.connectionstrings.com

Where do I find this table adaptar on the toolbox?

Edit: After reading your post: Are you sure your not doing the same thing I'm doing in my pictures? Because when I click the "New Connection" button in the data source configuration button nothing opens up and I'm tossed back to the form.

I know for a fact that a small window should open and allow me to select what type of database i have, etc.

Any help?

Sorry, I missed the part about the connection wizard not being invoked. I have read about that happening with VS.NET Express installations but i'm not sure as to the cause or solution. You didn't specify what type/verson of database you were trying to connect to so here are some functions to generate the connection string you need. If these do not suit your needs then post what DB you're using, and you are trying to get the Connection String, right? Not trying to figure out why the connection dialog won't open? Those are two different issues....

public static string BuildSqlNativeConnStr(string server, string database)
    {
      return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True;", server, database);
    }
    public static string BuildSqlNativeConnStr(string server, string database, string username, string password)
    {
      return string.Format("Data Source={0};Initial Catalog={1};Integrated Security=False;User Id={2};Password={3};", 
        server, 
        database,
        username,
        password);
    }
    public static string BuildExcelConnectionString(string Filename, bool FirstRowContainsHeaders)
    {
      return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';Extended Properties=\"Excel 8.0;HDR={1};\"",
                          Filename.Replace("'", "''"),
                          FirstRowContainsHeaders ? "Yes" : "No");
    }
    public static string BuildExcel2007ConnectionString(string Filename, bool FirstRowContainsHeaders)
    {
      return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0;HDR={1}\";",
                            Filename.Replace("'", "''"),
                            FirstRowContainsHeaders ? "Yes" : "No");
    }
    public static string BuildAccessConnectionString(string Filename, string Username, string Password, string DatabasePassword)
    {
      return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';User Id={1};Password={2};Jet OLEDB:Database Password={3};",
                                   Filename.Replace("'", "''"),
                                   Username,
                                   Password,
                                   DatabasePassword);
    }
    public static string BuildAccess2007ConnectionString(string Filename, string DatabasePassword)
    {
      return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='{0}';Persist Security Info=False;Jet OLEDB:Database Password={1};",
                                 Filename.Replace("'", "''"),
                                 DatabasePassword);
    }
    public static string BuildODBCConnectionString(string DSN)
    {
      return string.Format("DSN={0}", DSN);
    }

Thank you for trying to help me out. :)

I am using SQL Server 2008 and Visual C# 2008 as my IDE.

I really don't understand what the code above does though. Any extra help? Pretty please. xD

It generates the connection string for you.... Do you have a local copy of SQL Server running? If so you should be able to hover your mouse over the icon in the lower right of your machine and it should look like "ComputerName" or "ComputerName\InstanceName"

So take that text and plug it in here:
Data Source=MyPCName\MyInstanceName; Initial Catalog= MyDatabaseName; Integrated Security=True;

Replace "MyPCName\MyInstanceName" with what you see when you hover your mouse, replace "MyDatabaseName" with the DB name you want to connect to

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.