Connection string...

I have an application with the following connection code where the database is uploaded to the application:
        '*** Create a connection string with the connection string builder object
        Dim conStrBldr As New SqlConnectionStringBuilder
        With conStrBldr
            .DataSource = ".\SQLExpress"
            .AttachDBFilename = "NORTHWIND.MDF"
            .IntegratedSecurity = True
        End With

Open in new window


Question: How can I modify this code where (the database is not included with the application) the connection string is:

Data Source=.;Initial Catalog=WSCGSoftware;Integrated Security=True

Thank you.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Johnny NewbeeCommented:
You tried not to include .AttachDBFilename but point out the exact location in .datasource?
i.e.
.datasource=app.path & "\your.mdf"
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
You mean like:

        '*** Create a connection string with the connection string builder object
        Dim conStrBldr As New SqlConnectionStringBuilder
        With conStrBldr
            .DataSource = app.path & "\WSCGSoftware.mdf"
            .IntegratedSecurity = True
        End With

Open in new window


Just use "app.path" as you have?

FYI, I also have:  csWSCGSoftware.xml

<?xml version="1.0" encoding="utf-8" ?>
<connection>
  Data Source=.;Initial Catalog=WSCGSoftware;Integrated Security=True
</connection>

Open in new window

0
Johnny NewbeeCommented:
Yes, you tried to run? Error?
0
CodeCruiserCommented:
Replace

.AttachDBFilename = "NORTHWIND.MDF"

in your code with following

.InitialCatalog = "WSCGSoftware"


BTW, I would suggest that you pick up the connection string from config file instead of building it in your code. That way, you would not have to change and recompile the code if any aspect of the connection string changes again.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.